Example #1
0
    async def dsc_set(self, ctx):
        if (not permChecks.check_full_access(ctx.author)
                and Config.get(self)['songmaster_role_id'] != 0
                and Config.get(self)['songmaster_role_id'] not in [role.id for role in ctx.author.roles]):
            raise commands.BotMissingAnyRole([*Config().FULL_ACCESS_ROLES, Config.get(self)['songmaster_role_id']])
        if Config.get(self)['channel_id'] != 0 and Config.get(self)['channel_id'] != ctx.channel.id:
            raise commands.CheckFailure()

        if ctx.invoked_subcommand is None:
            await ctx.send_help(self.dsc_set)
Example #2
0
    def load(self):
        """Loads the commands"""
        # Update from old config versions
        if "_prefix" in Storage.get(self):
            self.update_config_from_1_to_2(Storage.get(self))
        if "_prefix" in Config.get(self):
            self.update_config_from_1_to_2(Config.get(self))

        # actually load the commands
        for k in Storage.get(self).keys():
            self.commands[k] = Cmd.deserialize(k, Storage.get(self)[k])
Example #3
0
    async def dsc_winners(self, ctx):
        c = self.get_api_client()
        winners = c.get(Config.get(self)['winners_range'])

        w_msgs = []
        regex = re.compile(r"\d+")
        for w in winners[1:]:
            if w[0] is None or not w[0]:
                continue

            m0 = regex.findall(w[0])
            m2 = regex.findall(w[2])
            no = m0[0]
            dt = datetime(int(m0[2]), int(m0[1]), 1)
            participator_coutn = m0[3]
            winner_name = w[1]
            pts_winner = int(m2[0])
            pts_max = int(m2[1])
            pts_percentage = round(pts_winner / pts_max * 100)

            w_msgs.append(Lang.lang(self, 'winner_msg', no, winner_name, pts_winner, pts_max, pts_percentage,
                                    participator_coutn, dt.month, dt.year))

        for m in utils.paginate(w_msgs, Lang.lang(self, 'winner_prefix')):
            await ctx.send(m)
Example #4
0
 def _get_rule_link(self):
     try:
         c = self.get_api_client()
         values = c.get(Config.get(self)['rule_cell'])
         return values[0][0]
     except IndexError:
         self.log.error("Can't read rules link from Contestdoc sheet. "
                        "Is Google Sheets not reachable or do you set the wrong cell?")
         return ""
Example #5
0
    async def cmd_prefix(self, ctx, new_prefix=None):
        # get current prefix
        if new_prefix is None:
            example = random.choice(list(self.commands.keys()))
            await ctx.send(
                Lang.lang(self, 'current_prefix',
                          Config.get(self)['prefix'], example))
            return

        # set new prefix
        if not permChecks.check_full_access(ctx.author):
            await ctx.message.add_reaction(Lang.CMDERROR)
            raise commands.BotMissingAnyRole(Config().FULL_ACCESS_ROLES)

        if new_prefix == ctx.prefix:
            await ctx.message.add_reaction(Lang.CMDERROR)
            await ctx.send(Lang.lang(self, 'invalid_prefix'))
        else:
            Config.get(self)['prefix'] = new_prefix
            self.save()
            await ctx.message.add_reaction(Lang.CMDSUCCESS)
Example #6
0
def make_app():
    settings = {
        'cookie_secret': 'dfdfdfd',
        'xsrf_cookies': True,
        'debug': True
    }
    other_db = {
        'mongo': motor_tornado.MotorClient(**Config.get('MONGO_CONF')),
        'redis': redis.StrictRedis()
    }
    return tornado.web.Application([(r'/web', WebHandler, other_db),
                                    (r'/', HtmlHandler),
                                    (r'/static/(.*)', StaticHandler)],
                                   **settings)
Example #7
0
    async def about(self, ctx):
        about_msg = Lang.lang(self, 'about_version', Config.VERSION, self.bot.guild.name,
                              platform.system(), platform.release(), platform.version())

        if Config.get(self)['bot_info_link']:
            about_msg += Lang.lang(self, 'about_general_info', Config.get(self)['bot_info_link'])
        about_msg += Lang.lang(self, 'about_repo', Config.get(self).get('repo_link',
                                                                           Lang.lang(self, 'about_no_repo_link')))
        if Config.get(self)['privacy_notes_link']:
            lang = ""
            if Config.get(self)['privacy_notes_lang']:
                lang = " ({})".format(Config.get(self)['privacy_notes_lang'])
            about_msg += Lang.lang(self, 'about_privacy', Config.get(self)['privacy_notes_link'], lang)

        about_msg += Lang.lang(self, 'about_devs', "Costamiri, Fluggs, Gobo77")
        if Config.get(self)['profile_pic_creator']:
            about_msg += Lang.lang(self, 'about_pfp', Config.get(self)['profile_pic_creator'])

        about_msg += Lang.lang(self, 'about_thanks')

        await ctx.send(about_msg)
Example #8
0
    def __init__(self, bot):
        super().__init__(bot)
        self.can_reload = True
        bot.register(self)

        self.prefix = Config.get(self)['prefix']
        self.commands = {}

        self.load()

        @bot.listen()
        async def on_message(msg):
            if (msg.content.startswith(self.prefix)
                    and msg.author.id != self.bot.user.id
                    and not self.bot.ignoring.check_user(msg.author)
                    and permChecks.whitelist_check(msg.author)):
                await self.on_message(msg)
Example #9
0
    async def configdump(self, ctx, name):
        plugin = converter.get_plugin_by_name(self.bot, name)
        if plugin is None:
            await ctx.message.add_reaction(Lang.CMDERROR)
            await ctx.send("Plugin {} not found.".format(name))
            return
        await ctx.message.add_reaction(Lang.CMDSUCCESS)

        dump = pprint.pformat(Config.get(plugin), indent=4).split("\n")
        prefix = ""
        if not Config.has_structure(plugin):
            prefix = "**Warning: plugin {} does not have a config structure.** " \
                     "This is the default config.".format(name)
        for el in utils.paginate(dump,
                                 prefix=prefix,
                                 msg_prefix="```",
                                 msg_suffix="```"):
            await ctx.send(el)
Example #10
0
    async def dsc_set_config(self, ctx, key="", value=""):
        if not key and not value:
            await ctx.invoke(self.bot.get_command("configdump"), self.get_name())
            return

        if key and not value:
            key_value = Config.get(self).get(key, None)
            if key_value is None:
                await ctx.message.add_reaction(Lang.CMDERROR)
                await ctx.send(Lang.lang(self, 'key_not_exists', key))
            else:
                await ctx.message.add_reaction(Lang.CMDSUCCESS)
                await ctx.send(key_value)
            return

        if key == "channel_id":
            channel = None
            int_value = Config.get(self)['channel_id']
            try:
                int_value = int(value)
                channel = self.bot.guild.get_channel(int_value)
            except ValueError:
                pass
            if channel is None:
                Lang.lang(self, 'channel_id_int')
                await ctx.message.add_reaction(Lang.CMDERROR)
                return
            else:
                Config.get(self)[key] = int_value

        elif key == "songmaster_role_id":
            role = None
            int_value = Config.get(self)['songmaster_role_id']
            try:
                int_value = int(value)
                role = self.bot.guild.get_role(int_value)
            except ValueError:
                pass
            if role is None:
                Lang.lang(self, 'songmaster_id')
                await ctx.message.add_reaction(Lang.CMDERROR)
                return
            else:
                Config.get(self)[key] = int_value

        else:
            Config.get(self)[key] = value

        Config.save(self)
        await ctx.message.add_reaction(Lang.CMDSUCCESS)
Example #11
0
 def _get_doc_link(self):
     return "https://docs.google.com/spreadsheets/d/{}".format(Config.get(self)['contestdoc_id'])
Example #12
0
 def get_api_client(self):
     """Returns a client to access Google Sheets API for the dsc contestdoc sheet"""
     return sheetsclient.Client(Config.get(self)['contestdoc_id'])
     pass
Example #13
0
 async def cmd_guidelines(self, ctx):
     # await ctx.send("MAKE BETTER; <https://github.com/gobo7793/Geckarbot/wiki/Command-Guidelines>")
     await ctx.send("<{}>".format(Config.get(self)['guidelines']))