Esempio n. 1
0
    async def set(self, ctx, pref: str, value: str):
        """!settings set [pref] [value]
        Admin powers required"""
        language = prefs.getPref(ctx.message.server, "language")

        if pref in commons.defaultSettings.keys():
            try:
                if pref == "ducks_per_day":
                    maxCJ = int(125 + (ctx.message.server.member_count / (5 + (ctx.message.server.member_count / 300))))
                    if int(value) > maxCJ:
                        if ctx.message.author.id in commons.owners:
                            await comm.message_user(ctx.message, _("Bypassing the max_ducks_per_day check as you are the bot owner. It would have been `{max}`.", language).format(**{
                                "max": maxCJ
                            }))
                        else:
                            value = maxCJ
            except (TypeError, ValueError):
                await comm.message_user(ctx.message, _(":x: Incorrect value.", language))
                return

            if prefs.setPref(ctx.message.server, pref=pref, value=value):
                if pref == "ducks_per_day":
                    await ducks.planifie(ctx.message.channel)
                await comm.message_user(ctx.message, _(":ok: The setting {pref} has been set to `{value}` on this server.", language).format(**{
                    "value": prefs.getPref(ctx.message.server, pref),
                    "pref" : pref
                }))
            else:
                await comm.message_user(ctx.message, _(":x: Incorrect value.", language))
        else:
            await comm.message_user(ctx.message, _(":x: Invalid preference, maybe a typo? Check the list with `!settings list`", language))
Esempio n. 2
0
def addToStat(channel, player, stat, value, announce=True):
    cond = stat == "exp" and prefs.getPref(channel.server,
                                           "announce_level_up") and announce
    if cond:
        ancien_niveau = getPlayerLevel(channel, player)

    setStat(channel, player, stat, int(getStat(channel, player, stat)) + value)

    if cond:
        language = prefs.getPref(channel.server, "language")

        embed = discord.Embed(
            description=_("Level of {player} on #{channel}", language).format(
                **{
                    "player": player.name,
                    "channel": channel.name
                }))

        level = getPlayerLevel(channel, player)
        if ancien_niveau["niveau"] > level["niveau"]:
            embed.title = _("You leveled down!", language)
            embed.colour = discord.Colour.red()
        elif ancien_niveau["niveau"] < level["niveau"]:
            embed.title = _("You leveled up!", language)
            embed.colour = discord.Colour.green()
        else:
            return

        embed.set_thumbnail(url=player.avatar_url if player.
                            avatar_url else commons.bot.user.avatar_url)
        embed.url = 'https://api-d.com/'

        embed.add_field(name=_("Current level", language),
                        value=str(level["niveau"]) + " (" +
                        _(level["nom"], language) + ")")
        embed.add_field(name=_("Previous level", language),
                        value=str(ancien_niveau["niveau"]) + " (" +
                        _(ancien_niveau["nom"], language) + ")")
        embed.add_field(name=_("Shots accuracy", language),
                        value=str(level["precision"]))
        embed.add_field(name=_("Weapon fiability", language),
                        value=str(level["fiabilitee"]))
        embed.add_field(name=_("Exp points", language),
                        value=str(getStat(channel, player, "exp")))
        embed.set_footer(
            text='DuckHunt V2',
            icon_url='http://api-d.com/snaps/2016-11-19_10-38-54-q1smxz4xyq.jpg'
        )
        try:
            commons.bot.loop.create_task(
                commons.bot.send_message(channel, embed=embed))
        except:
            commons.logger.exception("error sending embed, with embed " +
                                     str(embed.to_dict()))
            commons.bot.loop.create_task(
                commons.bot.send_message(
                    channel,
                    _(
                        ":warning: There was an error while sending the embed, please check if the bot has the `embed_links` permission and try again!",
                        language)))
Esempio n. 3
0
    async def listm(self, ctx):
        """!settings modified"""
        language = prefs.getPref(ctx.message.server, "language")
        defaultSettings = commons.defaultSettings
        x = PrettyTable()

        x._set_field_names([
            _("Parameter", language),
            _("Value", language),
            _("Default value", language)
        ])
        for param in defaultSettings.keys():
            if prefs.getPref(ctx.message.server,
                             param) != defaultSettings[param]["value"]:
                x.add_row([
                    param,
                    prefs.getPref(ctx.message.server, param),
                    defaultSettings[param]["value"]
                ])

        await comm.message_user(
            ctx.message,
            _("List of modified parameters : \n```{table}```",
              language).format(
                  **{"table": x.get_string(sortby=_("Parameter", language))}))
Esempio n. 4
0
    async def view(self, ctx, pref: str):
        """!settings view [pref]"""
        language = prefs.getPref(ctx.message.server, "language")

        if pref in commons.defaultSettings.keys():
            await comm.message_user(ctx.message, _("The {pref} setting's value is set to `{value}` on this server.", language).format(**{
                "value": prefs.getPref(ctx.message.server, pref),
                "pref" : pref
            }))
        else:
            await comm.message_user(ctx.message, _(":x: Invalid preference, maybe a typo? Check the list with `!settings list`.", language))
Esempio n. 5
0
async def planifie(channel_obj: discord.Channel = None):
    now = int(time.time())
    thisDay = now - (now % 86400)
    seconds_left = 86400 - (now - thisDay)
    multiplicator = round(seconds_left / 86400, 5)
    if not channel_obj:
        logger.debug("Replanning")
        commons.bread = defaultdict(int)
        planification_ = {}
        if multiplicator == 0:
            multiplicator = 1
        servers = prefs.JSONloadFromDisk("channels.json")
        for server_ in list(servers.keys()):
            server = bot.get_server(str(server_))
            if not server:
                logger.debug("Non-existant server: " + str(server_))
                servers.pop(server_)
                scores.delServerPlayers(sid=server_)

            elif not "channels" in servers[server.id]:
                await comm.logwithinfos(server.default_channel, log_str="Server not configured: " + server.id)
                try:
                    await bot.send_message(server, "The bot is not configured properly, please check the config or contact Eyesofcreeper#4758 | https://discord.gg/2BksEkV")
                    await comm.logwithinfos(server.default_channel, log_str="Unconfigured message sent...")
                except:
                    await comm.logwithinfos(server.default_channel, log_str="Error sending the unconfigured message to the default channel on the server.")

            else:
                for channel_ in servers[server.id]["channels"]:
                    channel = server.get_channel(str(channel_))
                    if channel:
                        permissions = channel.permissions_for(server.me)
                        if permissions.read_messages and permissions.send_messages:
                            # logger.debug("Adding channel: {id} ({ducks_per_day} c/j)".format(**{
                            #    "id"           : channel.id,
                            #    "ducks_per_day": prefs.getPref(server, "ducks_per_day")
                            # }))
                            planification_[channel] = round(prefs.getPref(server, "ducks_per_day") * multiplicator)
                        else:
                            await comm.logwithinfos(channel, log_str="Error adding channel to planification: no read/write permissions!")
                    else:
                        pass
        commons.ducks_planned = planification_  # {"channel":[time objects]}
        prefs.JSONsaveToDisk(servers, "channels.json")

    else:
        commons.bread[channel_obj] = 0
        permissions = channel_obj.permissions_for(channel_obj.server.me)
        if permissions.read_messages and permissions.send_messages:
            pass
        else:
            await comm.logwithinfos(channel_obj, log_str="Error adding channel to planification: no read/write permissions!")
        commons.ducks_planned[channel_obj] = round(prefs.getPref(channel_obj.server, "ducks_per_day") * multiplicator)
Esempio n. 6
0
    async def reset(self, ctx, pref: str):
        """!settings reset [pref]
        Admin powers required"""
        language = prefs.getPref(ctx.message.server, "language")

        if pref in commons.defaultSettings.keys():
            prefs.setPref(ctx.message.server, pref)
            await comm.message_user(ctx.message, _(":ok: The setting {pref} has been reset to its defalut value: `{value}`.", language).format(**{
                "value": prefs.getPref(ctx.message.server, pref),
                "pref" : pref
            }))
        else:
            await comm.message_user(ctx.message, _(":x: Invalid preference, maybe a typo? Check the list with `!settings list`", language))
Esempio n. 7
0
    async def reload(self, ctx):
        await self.giveBackIfNeeded(ctx.message)
        message = ctx.message
        language = prefs.getPref(message.server, "language")

        if scores.getStat(message.channel, message.author, "confisque", default=False):
            await comm.message_user(message, _("Your weapon is confiscated.", language))
            return
        if scores.getStat(message.channel, message.author, "enrayee", default=False):
            await comm.message_user(message, _("You unjammed your weapon.", language))
            scores.setStat(message.channel, message.author, "enrayee", False)
            # TODO : simplifier
            if scores.getStat(message.channel, message.author, "balles", default=scores.getPlayerLevel(message.channel, message.author)["balles"]) > 0:
                return

        if scores.getStat(message.channel, message.author, "balles", default=scores.getPlayerLevel(message.channel, message.author)["balles"]) <= 0:
            if scores.getStat(message.channel, message.author, "chargeurs", default=scores.getPlayerLevel(message.channel, message.author)["chargeurs"]) > 0:
                scores.setStat(message.channel, message.author, "balles", scores.getPlayerLevel(message.channel, message.author)["balles"])
                scores.addToStat(message.channel, message.author, "chargeurs", -1)
                scores.addToStat(message.channel, message.author, "reloads", 1)
                greet = _("You reloaded your weapon.", language)
            else:
                greet = _("You don't have any ammo left!", language)
                scores.addToStat(message.channel, message.author, "reloads_without_chargers", 1)
        else:
            greet = _("You don't need to reload your weapon.", language)
            scores.addToStat(message.channel, message.author, "unneeded_reloads", 1)

        await comm.message_user(message, _("{greet} | Ammo in weapon: {balles_actuelles}/{balles_max} | Chargers left: {chargeurs_actuels}/{chargeurs_max}", language).format(**{
            "greet"            : greet,
            "balles_actuelles" : scores.getStat(message.channel, message.author, "balles", default=scores.getPlayerLevel(message.channel, message.author)["balles"]),
            "balles_max"       : scores.getPlayerLevel(message.channel, message.author)["balles"],
            "chargeurs_actuels": scores.getStat(message.channel, message.author, "chargeurs", default=scores.getPlayerLevel(message.channel, message.author)["chargeurs"]),
            "chargeurs_max"    : scores.getPlayerLevel(message.channel, message.author)["chargeurs"]
        }))
Esempio n. 8
0
    async def game_unban(self, ctx, member: discord.Member):
        """Unban someone from the bot on the current channel
        !game_unban [member]"""
        language = prefs.getPref(ctx.message.server, "language")

        scores.setStat(ctx.message.channel, member, "banned", False)
        await comm.message_user(ctx.message, _(":ok: Done, user unbanned. :eyes:", language))
Esempio n. 9
0
def getChannelId(channel):
    server = channel.server

    def getit():
        sql.execute(
            "SELECT id FROM channels WHERE server = %(server)s AND channel = %(channel)s",
            {
                'server':
                int(server.id),
                'channel': (0 if prefs.getPref(server, "global_scores") else
                            int(channel.id))
            })

    getit()
    result = sql.fetchone()

    if result:
        return result['id']
    else:
        sql.execute(
            "INSERT INTO channels (server, channel) VALUES (%(server)s, %(channel)s)",
            {
                'server':
                int(server.id),
                'channel': (0 if prefs.getPref(server, "global_scores") else
                            int(channel.id))
            })
        getit()

        return sql.fetchone()['id']
Esempio n. 10
0
    async def add_channel(self, ctx):
        """Add the current channel to the server
        !add_channel
        """
        language = prefs.getPref(ctx.message.server, "language")
        servers = prefs.JSONloadFromDisk("channels.json")
        if not "channels" in servers[ctx.message.server.id]:
            servers[ctx.message.server.id]["channels"] = []

        if not ctx.message.channel.id in servers[
                ctx.message.server.id]["channels"]:
            await comm.logwithinfos_ctx(
                ctx, "Adding channel {name} | {id} to channels.json...".format(
                    **{
                        "id": ctx.message.channel.id,
                        "name": ctx.message.channel.name
                    }))
            servers[ctx.message.server.id]["channels"] += [
                ctx.message.channel.id
            ]
            prefs.JSONsaveToDisk(servers, "channels.json")
            await ducks.planifie(ctx.message.channel)
            await comm.message_user(ctx.message,
                                    _(":robot: Channel added!", language))

        else:
            await comm.logwithinfos_ctx(ctx, "Channel exists")
            await comm.message_user(
                ctx.message,
                _(":x: This channel already exists in the game.", language))
Esempio n. 11
0
    async def del_admin(self, ctx, target: discord.Member):
        """!del_admin [target]
        Remove an admin from the server
        """
        language = prefs.getPref(ctx.message.server, "language")
        servers = prefs.JSONloadFromDisk("channels.json")
        if target.id in servers[ctx.message.server.id]["admins"]:
            servers[ctx.message.server.id]["admins"].remove(target.id)
            await comm.logwithinfos_ctx(ctx, "Deleting admin {admin_name} | {admin_id} from configuration file for server {server_name} | {server_id}.".format(**{
                "admin_name" : target.name,
                "admin_id"   : target.id,
                "server_name": ctx.message.server.name,
                "server_id"  : ctx.message.server.id
            }))
            await comm.message_user(ctx.message, _(":robot: OK, {name} is not an admin anymore!", language).format(**{
                "name": target.name
            }))

            prefs.JSONsaveToDisk(servers, "channels.json")


        else:
            await comm.message_user(ctx.message, _(":robot: {name} is not an admin!", language).format(**{
                "name": target.name
            }))
Esempio n. 12
0
 async def permissions(self, ctx):
     """Check permissions given to the bot. You'll need admin powers
     !permissions"""
     permissionsToHave = [
         "change_nicknames", "connect", "create_instant_invite",
         "embed_links", "manage_messages", "mention_everyone",
         "read_messages", "send_messages", "send_tts_messages"
     ]
     permissions_str = ""
     for permission, value in ctx.message.server.me.permissions_in(
             ctx.message.channel):
         if value:
             emo = ":white_check_mark:"
         else:
             emo = ":negative_squared_cross_mark:"
         if (value and permission in permissionsToHave) or (
                 not value and not permission in permissionsToHave):
             pass
         else:
             emo += ":warning:"
         permissions_str += "\n{value}\t{name}".format(
             **{
                 "value": emo,
                 "name": str(permission)
             })
     await comm.message_user(
         ctx.message,
         _("Permissions: {permissions}",
           prefs.getPref(
               ctx.message.server,
               "language")).format(**{"permissions": permissions_str}))
Esempio n. 13
0
 async def claimserver(self, ctx):
     """Sets yourself as an admin if there are no admin configured, IE: when you just added the bot to a server
     !claimserver"""
     language = prefs.getPref(ctx.message.server, "language")
     servers = prefs.JSONloadFromDisk("channels.json")
     if not ctx.message.server.id in servers:
         servers[ctx.message.server.id] = {}
     if not "admins" in servers[ctx.message.server.id] or not servers[
             ctx.message.server.id]["admins"]:
         servers[ctx.message.server.id]["admins"] = [ctx.message.author.id]
         await comm.logwithinfos_ctx(
             ctx,
             "Adding admin {admin_name} | {admin_id} to configuration file for server {server_name} | {server_id}."
             .format(
                 **{
                     "admin_name": ctx.message.author.name,
                     "admin_id": ctx.message.author.id,
                     "server_name": ctx.message.server.name,
                     "server_id": ctx.message.server.id
                 }))
         await comm.message_user(
             ctx.message,
             _(":robot: OK, you've been set as an admin!", language))
     else:
         await comm.logwithinfos_ctx(ctx, "An admin already exist")
         await comm.message_user(
             ctx.message,
             _(
                 ":x: This server has already been claimed! Try !add_admin instead.",
                 language))
     prefs.JSONsaveToDisk(servers, "channels.json")
Esempio n. 14
0
 async def dbtable(self, ctx):
     if not prefs.getPref(ctx.message.server, "global_scores"):
         await comm.message_user(
             ctx.message,
             str(ctx.message.server.id) + "-" + str(ctx.message.channel.id))
     else:
         await comm.message_user(ctx.message, str(ctx.message.server.id))
Esempio n. 15
0
async def spawn_duck(duck):
    servers = prefs.JSONloadFromDisk("channels.json", default="{}")
    try:
        if servers[duck["channel"].server.id]["detecteur"].get(duck["channel"].id, False):
            for playerid in servers[duck["channel"].server.id]["detecteur"][duck["channel"].id]:
                player = discord.utils.get(duck["channel"].server.members, id=playerid)
                try:
                    await bot.send_message(player, _("There is a duck on #{channel}", prefs.getPref(duck["channel"].server, "language")).format(**{
                        "channel": duck["channel"].name
                    }))
                    await comm.logwithinfos(duck["channel"], player, "Sending a duck notification")
                except:
                    await comm.logwithinfos(duck["channel"], player, "Error sending the duck notification")
                    pass

            servers[duck["channel"].server.id]["detecteur"].pop(duck["channel"].id)
            prefs.JSONsaveToDisk(servers, "channels.json")
    except KeyError:
        pass

    chance = random.randint(0, 100)
    if chance <= prefs.getPref(duck["channel"].server, "super_ducks_chance"):
        minl = prefs.getPref(duck["channel"].server, "super_ducks_minlife")
        maxl = prefs.getPref(duck["channel"].server, "super_ducks_maxlife")
        if minl != maxl:
            if maxl < minl:
                maxl, minl = minl, maxl
                await comm.logwithinfos(duck["channel"], None, "Minl and maxl swapped")
            life = random.randint(minl, maxl)
        else:
            life = minl

        duck["isSC"] = True
        duck["SCvie"] = life
        duck["level"] = life
    else:
        duck["isSC"] = False
        duck["level"] = 1
        duck["SCvie"] = 1

    await comm.logwithinfos(duck["channel"], None, "New duck: " + str(duck))
    duck["time"] = time.time()
    if prefs.getPref(duck["channel"].server, "emoji_ducks"):
        corps = prefs.getPref(duck["channel"].server, "emoji_used") + " < "
    else:
        corps = random.choice(commons.canards_trace) + "  " + random.choice(commons.canards_portrait) + "  "

    if prefs.getPref(duck["channel"].server, "randomize_ducks"):
        canard_str = corps + _(random.choice(commons.canards_cri), language=prefs.getPref(duck["channel"].server, "language"))
    else:
        canard_str = corps + "QUAACK"
    try:
        await bot.send_message(duck["channel"], canard_str, tts=prefs.getPref(duck["channel"].server, "tts_ducks"))
    except:
        pass
    commons.n_ducks_spawned += 1
    commons.ducks_spawned.append(duck)
Esempio n. 16
0
 async def deleteeverysinglescoreandstatonthischannel(self, ctx):
     """Delete scores and stats of players on this channel. You'll need admin powers
     !deleteeverysinglescoreandstatonthischannel"""
     scores.delChannelPlayers(ctx.message.channel)
     await comm.message_user(
         ctx.message,
         _(":ok: Scores / stats of the channel were successfully deleted.",
           prefs.getPref(ctx.message.server, "language")))
Esempio n. 17
0
    async def list(self, ctx):
        """!settings list"""
        language = prefs.getPref(ctx.message.server, "language")

        await comm.message_user(
            ctx.message,
            _(
                "The list of preferences is available on our new website: https://api-d.com/bot-settings.html",
                language))
Esempio n. 18
0
 async def duckplanning(self, ctx):
     """!duckplanning
     DEPRECATED! Get the number of ducks left to spawn on the channel
     """
     await comm.message_user(
         ctx.message,
         _("There are {ducks} ducks left to spawn today!",
           prefs.getPref(ctx.message.server, "language")).format(
               ducks=commons.ducks_planned[ctx.message.channel]))
Esempio n. 19
0
 async def del_channel(self, ctx):
     """!del_channel
     Remove the current channel from the server
     """
     await ducks.del_channel(ctx.message.channel)
     await comm.message_user(
         ctx.message,
         _(":ok: Channel deleted.",
           prefs.getPref(ctx.message.server, "language")))
Esempio n. 20
0
    async def settings(self, ctx):
        language = prefs.getPref(ctx.message.server, "language")

        if not ctx.invoked_subcommand:
            await comm.message_user(
                ctx.message,
                _(
                    ":x: Incorrect syntax. Use the command this way: `!settings [view/set/reset/list/modified] [setting if applicable]`",
                    language))
Esempio n. 21
0
 def getit():
     sql.execute(
         "SELECT id FROM channels WHERE server = %(server)s AND channel = %(channel)s",
         {
             'server':
             int(server.id),
             'channel': (0 if prefs.getPref(server, "global_scores") else
                         int(channel.id))
         })
Esempio n. 22
0
    async def sendBangMessage(self, message: discord.Message, string: str):
        lag = prefs.getPref(message.server, "bang_lag")
        if lag > 0:
            tmp = await self.bot.send_message(message.channel, str(message.author.mention) + " > BANG")
            await asyncio.sleep(lag)
            await self.bot.edit_message(tmp, str(message.author.mention) + " > " + string)

        else:
            await comm.message_user(message, string)
Esempio n. 23
0
 def check(ctx, warn):
     owner = is_owner_check(ctx.message)
     if not owner and warn:
         commons.bot.loop.create_task(
             comm.message_user(
                 ctx.message,
                 _(
                     ":x: You can't use this command, you're not the bot owner!",
                     prefs.getPref(ctx.message.server, "language"))))
     return owner
Esempio n. 24
0
 def check(ctx, warn):
     admin = is_owner_check(ctx.message) or is_admin_check(ctx.message)
     if not admin and warn:
         commons.bot.loop.create_task(
             comm.message_user(
                 ctx.message,
                 _(
                     ":x: You can't use this command, you're not an admin on this server!",
                     prefs.getPref(ctx.message.server, "language"))))
     return admin
Esempio n. 25
0
 def check(ctx, exp, warn):
     exp_ = have_exp_check(ctx.message, exp)
     if not exp_ and warn:
         commons.bot.loop.create_task(
             comm.message_user(
                 ctx.message,
                 _(
                     ":x: You can't use this command, you need at least {exp} exp points!",
                     prefs.getPref(ctx.message.server,
                                   "language")).format(**{"exp": exp})))
     return exp_
Esempio n. 26
0
File: api.py Progetto: swhitt/DHV2
async def guild(ctx: HTTPRequestContext, server_id: str):
    await commons.bot.wait_until_ready()

    server = commons.bot.get_server(server_id)

    if server:
        player_count = 0
        channels = []

        global_scores = prefs.getPref(server, "global_scores")

        stats = defaultdict(int)

        if not global_scores:
            for channel in server.channels:
                activated = checks.is_activated_check(channel)
                if activated and channel.type == ChannelType.text:
                    table = scores.getChannelPlayers(channel,
                                                     columns=['shoots_fired'])
                    for member in table:
                        if checks.is_player_check(member):
                            channels.append({
                                "id": channel.id,
                                "name": channel.name
                            })
                            break

            channels.sort(key=lambda x: x['name'])

            resp = {
                "server": {
                    "name": server.name,
                    "channels": channels
                },
                "global_scores": global_scores
            }
        else:
            data = await list_members(server_id, server_id)

            if data:
                resp = {
                    "server": {
                        "id": data['server'].id,
                        "name": data['server'].name
                    },
                    "players": data['players'],
                    "global_scores": global_scores
                }
            else:
                return await prepare_resp(None, 404)  # Error

        return await prepare_resp(resp)
    else:
        return await prepare_resp(None, 404)  # Guild not found
Esempio n. 27
0
    async def time(self, ctx):
        time_data = int(time.time()) % 86400
        hour = str(int(time_data / 60 / 60)).rjust(2, "0")
        minutes = str(int(time_data / 60 % 60)).rjust(2, "0")
        seconds = str(int(time_data % 60)).rjust(2, "0")

        await comm.message_user(
            ctx.message,
            _("It's {hour}:{minutes}:{seconds}.",
              getPref(ctx.message.server, "language")).format(hour=hour,
                                                              minutes=minutes,
                                                              seconds=seconds))
Esempio n. 28
0
async def allCanardsGo():
    for canard in commons.ducks_spawned:
        try:
            await bot.send_message(
                canard["channel"],
                _(random.choice(commons.canards_bye),
                  language=getPref(canard["channel"].server, "language")))
            await logwithinfos(canard["channel"], None,
                               "Force-leaving of duck " + str(canard))
        except:
            await logwithinfos(canard["channel"], None,
                               "Force-leaving of duck FAILED " + str(canard))
            logger.exception("Here is why : ")
Esempio n. 29
0
 async def give_exp(self, ctx, target: discord.Member, exp: int):
     """Give exp to a player.
     Require admin powers
     !give_exp [target] [exp]"""
     try:
         scores.addToStat(ctx.message.channel, target, "exp", exp)
     except OverflowError:
         await comm.message_user(
             ctx.message,
             _(
                 "Congratulations, you sent / gave more experience than the maximum number I'm able to store.",
                 prefs.getPref(ctx.message.server, "language")))
         return
     await comm.logwithinfos_ctx(
         ctx, "[giveexp] Giving " + str(exp) + " exp points to " +
         target.mention)
     await comm.message_user(
         ctx.message,
         _(":ok:, they now have {newexp} exp points!",
           prefs.getPref(ctx.message.server, "language")).format(**{
               "newexp":
               scores.getStat(ctx.message.channel, target, "exp")
           }))
Esempio n. 30
0
    async def purge_messages_criteria(self, ctx, *, remove: str):
        language = prefs.getPref(ctx.message.server, "language")
        import datetime
        weeks = datetime.datetime.now() - datetime.timedelta(days=13)

        if ctx.message.channel.permissions_for(ctx.message.server.me).manage_messages:
            def check(m):
                return remove in m.content and not m.timestamp < weeks

            deleted = await ctx.bot.purge_from(ctx.message.channel, limit=100, check=check)
            await comm.message_user(ctx.message, _("{deleted} message(s) deleted", language).format(**{
                "deleted": len(deleted)
            }))
        else:
            await comm.message_user(ctx.message, _("No messages deleted: permission denied.", language))