Exemple #1
0
async def on_message(message):
    msg = message.content.strip()
    if not message.author.bot:
        if database.get_user(message.author.id) is not None:
            if message.author.id in user_time_dict.keys():
                if datetime.datetime.utcnow() - user_time_dict[
                        message.author.id] > datetime.timedelta(minutes=1):
                    database.add_balance(message.author,
                                         int(random.uniform(9, 15)))
                    user_time_dict[
                        message.author.id] = datetime.datetime.utcnow()
            else:
                user_time_dict[message.author.id] = datetime.datetime.utcnow()
        else:
            database.init_user(message.author)
            database.add_balance(message.author, 50)
    server_id = int(message.server.id)
    if message.server.id == 542778736857317386 and message.id not in [
            542783664023535616
    ]:
        pass
    if msg.startswith(database.get_prefix(server_id)):
        _command = msg.split(" ")[0].lower()
        args = re.sub(" +", " ", msg).split(" ")[1:]
        # clean_command = re.sub(get_prefix(hash(message.server)), "", _command)
        prefix = database.get_prefix(server_id)
        clean_command = _command[(len(prefix)):]
        for k in database.command_alias:
            if clean_command in k[0]:
                clean_command = k[1]
                break
        try:
            print(
                f"{message.author.name} runs {clean_command.capitalize()}Command with {args}"
            )
            mod = __import__("commands",
                             fromlist=[f"{clean_command.capitalize()}Command"])
            comm = getattr(mod, f"{clean_command.capitalize()}Command")
            b = comm(client, message.server, message, message.author, args)
            a = b.do()
            if isinstance(a, tuple):
                text, embed = a
            else:
                text = a
                embed = None
            #if text is None:
            #    text = ""
            a = await client.send_message(destination=message.channel,
                                          content=text,
                                          embed=embed)
        except Exception:
            print(f"Exception!")
            logging.exception(Exception)
    """
def prefix(bot, message):
    if DATABASE_URL and message.guild and any(name in message.content
                                              for name in command_names):
        prefix = db.get_prefix(message.guild.id)
        if prefix:
            return prefix
    return '-'
    async def on_message(self, message):
        if message.author.id in cmds.BOT_IDS:
            return

        split = message.content.split(' ', 1)  # separate mom?[cmd] from args
        cmd = split[0]
        args = split[1].split(' ') if len(split) > 1 else None

        # Retrieve user from database and create if non-existing
        user = db.user_exists(message.author.id)
        if not user:
            db.adduser(message.author.id)
        prefix = db.get_prefix(message.author.id)

        # Check if a bot command
        if not cmd.startswith(f"mom{prefix}"):
            return

        # Debugging stuff
        name = author_name(message.author)
        print(f"{name} issued {cmd} command. <{args}>")

        cur_cmd = None
        try:
            suffix = cmd[4:]  # Get command suffix
            cur_cmd = COMMANDS[suffix]['cmd']
            await cur_cmd(self, message, args)
        except Exception as error:
            if not cur_cmd:
                return await cmds.error_message(message, title=f"Unknown command '{suffix}'")
            cmds.ERRORS += [time.ctime() + ': ' + str(error)]
            cmd = cmds.format_cmd(prefix, "report")
            await cmds.error_message(message,
                                     title=f"The command {suffix} failed...",
                                     desc=f"Please use ``{cmd}`` if you think it's an unexpected behaviour")
Exemple #4
0
    def do(self):
        super().do()
        embed = discord.Embed(title=f"List of Commands",
                              color=discord.Color.dark_blue())
        # change the values so they work in discord.py
        embed.set_author(
            name="by RainDance",
            icon_url=
            "https://poketouch.files.wordpress.com/2016/08/freeze_pokemon_articuno.png?w=648"
        )

        a = [
            "Until I get a reliable host that's not my computer, this will shut down at random moments, so RIP",
            "!start - Do this to start your card game adventure.",
            "!auction, !a, !auc - Auction a card for sale.",
            "!balance, !bal - Check your money.",
            "!buy - Buy a pack, run '!buy' for more details.",
            "!cards, !c - Find out your list of cards.",
            "!cardslist, !clist - Find out the total list of cards.",
            "!help - This command.",
            "!pay, !p - Pay someone of your choice an amount of money.",
            "!prefix, !pr - Change the server prefix or view the current.",
            "!sell, !s - Sell a card for money.",
            "!gamble, !g - Gamble an amount of money to have a"
            " chance to get a card not defined by traditional rarities.",
        ]
        print(f"PREFIX: {database.get_prefix(self.server.id)}")
        embed.add_field(name="Commands",
                        value=(("\n".join(a)).replace(
                            "!", database.get_prefix(self.server.id)).replace(
                                ".", "!")),
                        inline=False)
        return None, embed
Exemple #5
0
async def get_group_ics(message, group, week=None):
    if not group:
        cmd = format_cmd(db.get_prefix(message.author.id), "set")
        return await error_message(message,
                                   "You don't have any default group set",
                                   f"Please check the ``{cmd}`` command.")

    ics = get_ics_feed(group) if week == None else get_ics_week(group, week)
    if not ics:
        return await error_message(
            message, f"The group '{group}' does not exist",
            "Please refer to existing iChronos groups.")

    return ics
Exemple #6
0
 def do(self):
     super().do()
     server_id = int(self.server.id)
     my_id = 223212153207783435
     if len(self.args) == 0:
         return f"Current Prefix: {get_prefix(server_id)}"
     elif len(self.args) == 1:
         print(
             f"{int(self.sender.id)} is {my_id} {my_id != int(self.sender.id)}"
         )
         if int(self.sender.id) != my_id:
             if not self.sender.server_permissions.administrator or \
                     self.sender != self.server.owner:
                 return "You must be the server owner to set this"
         former = get_prefix(server_id)
         set_prefix(server_id, self.args[0])
         return f"Prefix changed from {former} to {get_prefix(server_id)}"
     else:
         return f"command {self.name} has too many arguments ( {self.args})"