示例#1
0
 async def setDuration(self, ctx: commands.Context, event: Event,
                       duration: int, durationtype: str, closingtime: int,
                       closingtimetype: str):
     newDuration = Util.convertToSeconds(duration, durationtype)
     newClosing = Util.convertToSeconds(closingtime, closingtimetype)
     dbc = self.bot.DBC
     dbc.query('UPDATE events set duration=%d, closingTime=%d WHERE ID=%d' %
               (newDuration, newClosing, event["ID"]))
     await ctx.send(
         f"Event {event['name']} duration is now {duration} {durationtype} and submissions will be closed {closingtime} {closingtimetype} in advance."
     )
示例#2
0
 async def create(self, ctx: commands.Context, name: str, duration: int,
                  durationtype: str, closingtime: int,
                  closingtimetype: str):
     """Creates a new event"""
     duration = Util.convertToSeconds(duration, durationtype)
     closingtime = Util.convertToSeconds(closingtime, closingtimetype)
     dbc = self.bot.DBC
     name = dbc.escape(name)
     dbc.query(
         "INSERT INTO events (name, duration, closingTime) VALUES ('%s', %d, %d)"
         % (name, duration, closingtime))
     id = dbc.connection.insert_id()
     await ctx.send(f"Event `{name}` created with ID `{id}`.")
示例#3
0
 async def mute(self,
                ctx: commands.Context,
                target: discord.Member,
                durationNumber: int,
                durationIdentifier: str,
                *,
                reason="No reason provided"):
     """Temporary mutes someone"""
     roleid = Configuration.getConfigVar(ctx.guild.id, "MUTE_ROLE")
     if roleid is 0:
         await ctx.send(
             f":warning: Unable to comply, you have not told me what role i can use to mute people, but i can still kick {target.mention} if you want while a server admin tells me what role i can use"
         )
     else:
         role = discord.utils.get(ctx.guild.roles, id=roleid)
         if role is None:
             await ctx.send(
                 f":warning: Unable to comply, someone has removed the role i was told to use, but i can still kick {target.mention} while a server admin makes a new role for me to use"
             )
         else:
             duration = Util.convertToSeconds(durationNumber,
                                              durationIdentifier)
             until = time.time() + duration
             await target.add_roles(
                 role,
                 reason=f"{reason}, as requested by {ctx.author.name}")
             if not str(ctx.guild.id) in self.mutes:
                 self.mutes[str(ctx.guild.id)] = dict()
             self.mutes[str(ctx.guild.id)][str(target.id)] = until
             await ctx.send(f"{target.display_name} has been muted")
             Util.saveToDisk("mutes", self.mutes)
             await BugLog.logToModLog(
                 ctx.guild,
                 f":zipper_mouth: {target.name}#{target.discriminator} (`{target.id}`) has been muted by {ctx.author.name} for {durationNumber} {durationIdentifier}: {reason}"
             )
示例#4
0
 async def tempban(self,
                   ctx: commands.Context,
                   user: discord.Member,
                   durationNumber: int,
                   durationIdentifier: str,
                   *,
                   reason="No reason provided."):
     """Temporarily bans someone."""
     if user == ctx.bot.user:
         await ctx.send(
             "Why would you like to tempban me? :disappointed_relieved:")
     elif user == ctx.author:
         await ctx.send(
             "You have played yourself. But you cannot tempban yourself!")
     else:
         duration = Util.convertToSeconds(durationNumber,
                                          durationIdentifier)
         until = time.time() + duration
         await ctx.guild.ban(
             user,
             reason=
             f"Moderator: {ctx.author.name} ({ctx.author.id}), Duration: {durationNumber}{durationIdentifier} Reason: {reason}"
         )
         await ctx.send(
             f":ok_hand: {user.name} ({user.id}) has been banned for {durationNumber}{durationIdentifier}(``{reason}``)"
         )
         await asyncio.sleep(duration)
         await ctx.guild.unban(
             user,
             reason=
             f"Moderator: {ctx.author.name} ({ctx.author.id}). Their temporary ban has expired."
         )
示例#5
0
 async def temprole(self, ctx: commands.Context, user: discord.Member,
                    durationNumber: int, durationIdentifier: str, *,
                    rolename: str):
     """Gives a role to someone temporarily."""
     role = discord.utils.find(lambda m: rolename.lower() in m.name.lower(),
                               ctx.guild.roles)
     duration = Util.convertToSeconds(durationNumber, durationIdentifier)
     until = time.time() + duration
     if not role:
         await ctx.send("That role doesn't exist, try again?")
     try:
         await user.add_roles(role)
         await ctx.send(
             f"Added {role.name} to {user} for {durationNumber}{durationIdentifier}."
         )
         await asyncio.sleep(duration)
         await user.remove_roles(role)
     except discord.Forbidden:
         await ctx.send("I need **Manage Roles** for this.")