Add away.py
Thanks to Axas.
This commit is contained in:
7
away/__init__.py
Normal file
7
away/__init__.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from discord.ext import commands
|
||||
from .away import Away
|
||||
|
||||
|
||||
def setup(bot: commands.Bot):
|
||||
n = Away(bot)
|
||||
bot.add_cog(n)
|
||||
87
away/away.py
Normal file
87
away/away.py
Normal file
@@ -0,0 +1,87 @@
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
|
||||
from redbot.core import Config
|
||||
from redbot.core.bot import Red
|
||||
|
||||
|
||||
class Away:
|
||||
"""Le away cog"""
|
||||
|
||||
default_global_settings = {
|
||||
"ign_servers": []
|
||||
}
|
||||
default_user_settings = {
|
||||
"MESSAGE": False
|
||||
}
|
||||
|
||||
def __init__(self, bot: Red):
|
||||
self.bot = bot
|
||||
self._away = Config.get_conf(self, 8423491260, force_registration=True)
|
||||
|
||||
self._away.register_global(**self.default_global_settings)
|
||||
self._away.register_user(**self.default_user_settings)
|
||||
|
||||
async def on_message(self, message):
|
||||
tmp = {}
|
||||
guild = message.guild
|
||||
list_of_guilds_ign = await self._away.ign_servers()
|
||||
if not guild:
|
||||
return
|
||||
if guild.id not in list_of_guilds_ign:
|
||||
for mention in message.mentions:
|
||||
tmp[mention] = True
|
||||
if message.author.id != guild.me.id:
|
||||
for author in tmp:
|
||||
test = await self._away.user(author).MESSAGE()
|
||||
if test:
|
||||
try:
|
||||
avatar = author.avatar_url if author.avatar else author.default_avatar_url
|
||||
|
||||
if test:
|
||||
em = discord.Embed(description=test, color=discord.Color.blue())
|
||||
em.set_author(name='{} is currently away'.format(author.display_name), icon_url=avatar)
|
||||
else:
|
||||
em = discord.Embed(color=discord.Color.blue())
|
||||
em.set_author(name='{} is currently away'.format(author.display_name), icon_url=avatar)
|
||||
await message.channel.send(embed=em)
|
||||
except:
|
||||
if test:
|
||||
msg = '{} is currently away and has set the following message: `{}`'.format(author.display_name, test)
|
||||
else:
|
||||
msg = '{} is currently away'.format(author.display_name)
|
||||
await message.channel.send(msg)
|
||||
|
||||
@commands.command(name="away")
|
||||
async def away_(self, ctx, *message):
|
||||
"""Tell the bot you're away or back."""
|
||||
author = ctx.message.author
|
||||
mess = await self._away.user(author).MESSAGE()
|
||||
if mess:
|
||||
await self._away.user(author).clear()
|
||||
msg = 'You\'re now back.'
|
||||
else:
|
||||
length = len(str(message))
|
||||
if length < 256 and length > 2:
|
||||
await self._away.user(author).MESSAGE.set(' '.join(ctx.message.clean_content.split()[1:]))
|
||||
else:
|
||||
await self._away.user(author).MESSAGE.set(' ')
|
||||
msg = 'You\'re now set as away.'
|
||||
await ctx.send(msg)
|
||||
|
||||
@commands.command(name="toggleaway")
|
||||
@commands.has_permissions(administrator=True)
|
||||
async def _ignore(self, ctx):
|
||||
"""Toggle away messages on the whole server."""
|
||||
guild = ctx.message.guild
|
||||
if guild.id in (await self._away.ign_servers()):
|
||||
guilds = await self._away.ign_servers()
|
||||
guilds.remove(guild.id)
|
||||
await self._away.ign_servers.set(guilds)
|
||||
message = 'Not ignoring this guild anymore.'
|
||||
else:
|
||||
guilds = await self._away.ign_servers()
|
||||
guilds.append(guild.id)
|
||||
await self._away.ign_servers.set(guilds)
|
||||
message = 'Ignoring this guild.'
|
||||
await ctx.send(message)
|
||||
11
away/info.json
Normal file
11
away/info.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"author": [
|
||||
"Axas and aikaterna"
|
||||
],
|
||||
"description": "Set and unset a user as being away.",
|
||||
"short": "Away message toggle for users",
|
||||
"tags": [
|
||||
"away"
|
||||
],
|
||||
"type": "COG"
|
||||
}
|
||||
Reference in New Issue
Block a user