import io import math import re import discord from discord.ext import commands from discord.ext.commands import BucketType from objects.glimcontext import GlimContext from utils import colors, http, render, sqlite as sql, utils from objects.logger import Log from objects import errors log = Log(__name__) class Canvas: def __init__(self, bot): self.bot = bot # ======================= # DIFF # ======================= @commands.cooldown(1, 5, BucketType.guild) @commands.group(name="diff", invoke_without_command=True, aliases=["d"]) async def diff(self, ctx, *args): if len(args) < 1: return list_pixels = False iter_args = iter(args)
def __init__(self, bot): self.bot = bot self.log = Log(__name__)
class Configuration: def __init__(self, bot): self.bot = bot self.log = Log(__name__) @checks.admin_only() @commands.guild_only() @commands.group(name="alertchannel", invoke_without_command=True) async def alertchannel(self, ctx): channel = dget(ctx.guild.channels, id=sql.guild_get_by_id(ctx.guild.id).alert_channel) if channel: await ctx.send("Alert channel is currently set to {0}.".format(channel.mention)) else: await ctx.send("No alert channel has been set.") @checks.admin_only() @commands.guild_only() @alertchannel.command(name="set") async def alertchannel_set(self, ctx, channel: TextChannel): sql.guild_update(ctx.guild.id, alert_channel=channel.id) self.log.info("Alert channel for {0.name} set to {1.name} (GID:{0.id} CID:{1.name})".format(ctx.guild, channel)) await ctx.send(ctx.s("configuration.alert_channel_set").format(channel.mention)) @checks.admin_only() @commands.guild_only() @alertchannel.command(name="clear") async def alertchannel_clear(self, ctx): sql.guild_update(ctx.guild.id, alert_channel=0) self.log.info("Alert channel for {0.name} cleared (GID:{0.id})".format(ctx.guild)) await ctx.send(ctx.s("configuration.alert_channel_cleared")) @checks.admin_only() @commands.guild_only() @commands.command() async def prefix(self, ctx, prefix): if len(prefix) > 5: raise commands.BadArgument sql.guild_update(ctx.guild.id, prefix=prefix) self.log.info("Prefix for {0.name} set to {1} (GID: {0.id})".format(ctx.guild, prefix)) await ctx.send(ctx.s("configuration.prefix_set").format(prefix)) @checks.admin_only() @commands.guild_only() @commands.command() async def autoscan(self, ctx): if sql.guild_is_autoscan(ctx.guild.id): sql.guild_update(ctx.guild.id, autoscan=1) self.log.info("Autoscan enabled for {0.name} (GID: {0.id})".format(ctx.guild)) await ctx.send(ctx.s("configuration.autoscan_enabled")) else: sql.guild_update(ctx.guild.id, autoscan=0) self.log.info("Autoscan disabled for {0.name} (GID: {0.id})".format(ctx.guild)) await ctx.send(ctx.s("configuration.autoscan_disabled")) @checks.admin_only() @commands.guild_only() @commands.group(name="canvas", invoke_without_command=True) async def canvas(self, ctx): out = [ctx.s("configuration.canvas_check_1").format(ctx.canvas_pretty), ctx.s("configuration.canvas_check_2").format(ctx.prefix)] await ctx.send('\n'.join(out)) @checks.admin_only() @commands.guild_only() @canvas.command(name="pixelcanvas", aliases=["pc"]) async def canvas_pixelcanvas(self, ctx): sql.guild_update(ctx.guild.id, canvas="pixelcanvas") self.log.info("Default canvas for {0.name} set to pixelcanvas (GID:{0.id})".format(ctx.guild)) await ctx.send(ctx.s("configuration.canvas_set").format("Pixelcanvas.io")) @checks.admin_only() @commands.guild_only() @canvas.command(name="pixelzone", aliases=["pz"]) async def canvas_pixelzone(self, ctx): sql.guild_update(ctx.guild.id, canvas="pixelzone") self.log.info("Default canvas for {0.name} set to pixelzone (GID:{0.id})".format(ctx.guild)) await ctx.send(ctx.s("configuration.canvas_set").format("Pixelzone.io")) @checks.admin_only() @commands.guild_only() @canvas.command(name="pxlsspace", aliases=["ps"]) async def canvas_pxlsspace(self, ctx): sql.guild_update(ctx.guild.id, canvas="pxlsspace") self.log.info("Default canvas for {0.name} set to pxlsspace (GID:{0.id})".format(ctx.guild)) await ctx.send(ctx.s("configuration.canvas_set").format("Pxls.space")) @checks.admin_only() @commands.guild_only() @commands.command() async def language(self, ctx, option=None): if not option: out = [ ctx.s("configuration.language_check_1").format(ctx.langs[ctx.lang]), ctx.s("configuration.language_check_2"), "```" ] for code, name in ctx.langs.items(): out.append("{0} - {1}".format(code, name)) out.append("```") await ctx.send('\n'.join(out)) return if option.lower() not in ctx.langs: return sql.guild_update(ctx.guild.id, language=option.lower()) self.log.info("Language for {0.name} set to {1} (GID:{0.id})".format(ctx.guild, option.lower())) await ctx.send(ctx.s("configuration.language_set").format(ctx.langs[option.lower()])) @checks.admin_only() @commands.guild_only() @commands.group(name="role", invoke_without_command=True) async def role(self, ctx): roles = ["botadmin", "templateadder", "templateadmin"] out = ["**{}**".format(ctx.s("configuration.role_list_header")), "```xl"] max_len = max(map(lambda x: len(x), roles)) for r in roles: out.append("{0:<{max_len}} - {1}".format(r, ctx.s("configuration.role_list_" + r), max_len=max_len)) out.append("```") await ctx.send('\n'.join(out)) @checks.admin_only() @commands.guild_only() @role.group(name="botadmin", invoke_without_command=True) async def role_botadmin(self, ctx): r = utils.get_botadmin_role(ctx) if r: await ctx.send(ctx.s("configuration.role_bot_admin_check").format(r.name)) else: await ctx.send(ctx.s("configuration.role_bot_admin_not_set")) @checks.admin_only() @commands.guild_only() @role_botadmin.command(name="set") async def role_botadmin_set(self, ctx, role=None): m = re.match('<@&(\d+)>', role) r = dget(ctx.guild.roles, id=int(m.group(1))) if m else dget(ctx.guild.roles, name=role) if r: sql.guild_update(ctx.guild.id, bot_admin=r.id) await ctx.send(ctx.s("configuration.role_bot_admin_set").format(r.name)) else: await ctx.send(ctx.s("configuration.role_not_found")) @checks.admin_only() @commands.guild_only() @role_botadmin.command(name="clear") async def role_botadmin_clear(self, ctx): sql.guild_update(ctx.guild.id, bot_admin=None) await ctx.send(ctx.s("configuration.role_bot_admin_cleared")) @checks.admin_only() @commands.guild_only() @role.group(name="templateadder", invoke_without_command=True) async def role_templateadder(self, ctx): r = utils.get_templateadder_role(ctx) if r: await ctx.send(ctx.s("configuration.role_template_adder_check").format(r.name)) else: await ctx.send(ctx.s("configuration.role_template_adder_not_set")) @checks.admin_only() @commands.guild_only() @role_templateadder.command(name="set") async def role_templateadder_set(self, ctx, role=None): m = re.match('<@&(\d+)>', role) r = dget(ctx.guild.roles, id=int(m.group(1))) if m else dget(ctx.guild.roles, name=role) if r: sql.guild_update(ctx.guild.id, template_adder=r.id) await ctx.send(ctx.s("configuration.role_template_adder_set").format(r.name)) else: await ctx.send(ctx.s("configuration.role_not_found")) @checks.admin_only() @commands.guild_only() @role_templateadder.command(name="clear") async def role_templateadder_clear(self, ctx): sql.guild_update(ctx.guild.id, template_adder=None) await ctx.send(ctx.s("configuration.role_template_adder_cleared")) @checks.admin_only() @commands.guild_only() @role.group(name="templateadmin", invoke_without_command=True) async def role_templateadmin(self, ctx): r = utils.get_templateadmin_role(ctx) if r: await ctx.send(ctx.s("configuration.role_template_admin_check").format(r.name)) else: await ctx.send(ctx.s("configuration.role_template_admin_not_set")) @checks.admin_only() @commands.guild_only() @role_templateadmin.command(name="set") async def role_templateadmin_set(self, ctx, role=None): m = re.match('<@&(\d+)>', role) r = dget(ctx.guild.roles, id=int(m.group(1))) if m else dget(ctx.guild.roles, name=role) if r: sql.guild_update(ctx.guild.id, template_admin=r.id) await ctx.send(ctx.s("configuration.role_template_admin_set").format(r.name)) else: await ctx.send(ctx.s("configuration.role_not_found")) @checks.admin_only() @commands.guild_only() @role_templateadmin.command(name="clear") async def role_templateadmin_clear(self, ctx): sql.guild_update(ctx.guild.id, template_admin=None) await ctx.send(ctx.s("configuration.role_template_admin_cleared"))
from objects.channel_logger import ChannelLogger from objects.config import Config from objects.glimcontext import GlimContext from objects.help_formatter import GlimmerHelpFormatter from objects.logger import Log from utils import canvases, http, render, sqlite as sql, utils from utils.version import VERSION def get_prefix(bot_, msg: discord.Message): return [sql.guild_get_prefix_by_id(msg.guild.id), bot_.user.mention + " "] \ if msg.guild else [cfg.prefix, bot_.user.mention + " "] cfg = Config() log = Log(''.join(cfg.name.split())) bot = commands.Bot(command_prefix=get_prefix, formatter=GlimmerHelpFormatter()) bot.remove_command('help') ch_log = ChannelLogger(bot) extensions = [ "commands.animotes", "commands.canvas", "commands.configuration", "commands.faction", "commands.general", "commands.template", ] sql.menu_locks_delete_all() @bot.event
def __init__(self, bot): self.bot = bot self.ch_log = ChannelLogger(bot) self.cfg = Config() self.log = Log(__name__)
class General: def __init__(self, bot): self.bot = bot self.ch_log = ChannelLogger(bot) self.cfg = Config() self.log = Log(__name__) @commands.command() async def changelog(self, ctx): data = await http.get_changelog(VERSION) if not data: await ctx.send(ctx.s("general.err.cannot_get_changelog")) return e = discord.Embed(title=data['name'], url=data['url'], color=13594340, description=data['body']) \ .set_author(name=data['author']['login']) \ .set_thumbnail(url=data['author']['avatar_url']) \ .set_footer(text="Released " + data['published_at']) await ctx.send(embed=e) @commands.command() async def github(self, ctx): await ctx.send("https://github.com/DiamondIceNS/StarlightGlimmer") @commands.command(aliases=['h', 'commands']) async def help(self, ctx, *cmds: str): """Shows this message.""" bot = ctx.bot def repl(obj): return ctx.bot._mentions_transforms.get(obj.group(0), '') # help by itself just lists our own commands. if len(cmds) == 0: out = await self.bot.formatter.format_help_for(ctx, self.bot) elif len(cmds) == 1: # try to see if it is a cog name # name = _mention_pattern.sub(repl, commands[0]) # TODO: Filter @everyone here? name = cmds[0] command = bot.all_commands.get(name) if command is None: await ctx.send(bot.command_not_found.format(name)) return out = await self.bot.formatter.format_help_for(ctx, command) else: # name = _mention_pattern.sub(repl, commands[0]) name = cmds[0] command = bot.all_commands.get(name) if command is None: await ctx.send(bot.command_not_found.format(name)) return for key in cmds[1:]: try: # key = _mention_pattern.sub(repl, key) command = command.all_commands.get(key) if command is None: await ctx.send(bot.command_not_found.format(key)) return except AttributeError: await ctx.send( bot.command_has_no_subcommands.format(command, key)) return out = await bot.formatter.format_help_for(ctx, command) if out: await ctx.send('\n'.join(out)) @commands.command() async def invite(self, ctx): await ctx.send(self.cfg.invite) @commands.command() async def ping(self, ctx): ping_start = time() ping_msg = await ctx.send(ctx.s("general.ping")) ping_time = time() - ping_start self.log.debug("(Ping:{0}ms)".format(int(ping_time * 1000))) await ping_msg.edit( content=ctx.s("general.pong").format(int(ping_time * 1000))) @commands.cooldown(1, 5, BucketType.guild) @commands.command() async def suggest(self, ctx, *, suggestion: str): self.log.debug("Suggestion: {0}".format(suggestion)) await self.ch_log.log( "New suggestion from **{0.name}#{0.discriminator}** (ID: `{0.id}`) in guild " "**{1.name}** (ID: `{1.id}`):".format(ctx.author, ctx.guild)) await self.ch_log.log("> `{}`".format(suggestion)) await ctx.send(ctx.s("general.suggest")) @commands.command() async def version(self, ctx): await ctx.send(ctx.s("general.version").format(VERSION))