예제 #1
0
 async def responselimit(self, ctx: context, name: str, *tags: str):
     """Adds a restriction mode on a response so it only triggers in certain circumstances.
     Tags is a space-separated list of users and channels that this responder will apply to. These must be
     discord tags or pings, i.e. discord must show them as links, not just text.
     If the word NONE is used, all restrictions are removed.
     """
     comm = self._find_one(name)
     if not comm:
         await ctx.send(embed=mkembed('error', f"{name} does not exist."))
         return
     if not ctx.author.id == comm['creator_id']:
         await ctx.send(embed=mkembed(
             'error',
             f"You are not the creator of {name}. Ask {comm['creator_str']}"
         ))
         return
     if tags[0] == "NONE":
         comm["restrictions"] = {}
         self.backend.save(comm)
         await ctx.send(
             embed=mkembed('done', f"All restrictions removed from {name}"))
         return
     if ctx.message.mentions:
         if not comm.get("restrictions"):
             comm["restrictions"] = {}
         elif not comm["restrictions"].get("users"):
             comm["restrictions"]["users"] = []
         comm["restrictions"]["users"] = list(
             set(comm["restrictions"]["users"] +
                 [u.id for u in ctx.message.mentions]))
         self.backend.save(comm)
         display_users = [
             self.bot.get_user(u).display_name
             for u in comm["restrictions"]["users"]
         ]
         await ctx.send(embed=mkembed('done',
                                      'User restriction updated:',
                                      command=comm['command'],
                                      users=display_users))
     if ctx.message.channel_mentions:
         if not comm.get("restrictions"):
             comm["restrictions"] = {}
         if not comm["restrictions"].get("channels"):
             comm["restrictions"]["channels"] = []
         comm["restrictions"]["channels"] = list(
             set(comm["restrictions"]["channels"] +
                 [c.id for c in ctx.message.channel_mentions]))
         display_channels = [
             self.bot.get_channel(c).name
             for c in comm["restrictions"]["channels"]
         ]
         self.backend.save(comm)
         await ctx.send(embed=mkembed('done',
                                      'Channel restriction updated:',
                                      Command=comm['command'],
                                      Channels=display_channels))
예제 #2
0
 async def responserestrictions(self, ctx: context, name: str):
     """Show the restriction list for a given command"""
     comm = self._find_one(name)
     if not comm:
         await ctx.send(embed=mkembed('error', f"{name} does not exist."))
         return
     await ctx.send(
         embed=mkembed('info',
                       f"Information for `{name}`",
                       Reply=comm['reply'],
                       Restrictions=comm.get('restrictions', 'None'),
                       Creator=comm['creator_str']))
예제 #3
0
 async def addresponse(self, ctx: SlashContext, respond_to: str, response: str):
     """Adds an automatic response to (name) as (response)
     The first word (name) is the text that will be replied to. Everything else is what it will be replied to with.
     If you want to reply to an entire phrase, enclose name in quotes."""
     if self._find_one(respond_to):
         await ctx.send(embed=mkembed('error', f"'{respond_to}' already exists."))
         return
     else:
         comm = ResponseCommand(
             {'command': respond_to, 'reply': response, 'creator_str': str(ctx.author), 'creator_id': ctx.author.id}
         )
         self.backend.save(comm)
         self.bot.logger.info(f"'{response}' was added by {ctx.author.display_name}")
         await ctx.send(embed=mkembed('done', "Autoresponse saved.", reply_to=respond_to, reply_with=response))
예제 #4
0
 async def delresponse(self, ctx: SlashContext, respond_to: str):
     """Removes an autoresponse.
     Only the initial creator of a response can remove it."""
     comm = self._find_one(respond_to)
     if not comm:
         await ctx.send(embed=mkembed('error', f"{respond_to} is not defined."))
         return
     elif not ctx.author.id == comm['creator_id']:
         await ctx.send(
             embed=mkembed('error', f"You are not the creator of {respond_to}. Ask {comm['creator_str']}"))
     else:
         self.backend.delete(comm)
         self.bot.logger.info(f"'{respond_to}' was deleted by {ctx.author.display_name}")
         await ctx.send(embed=mkembed('info', f"{respond_to} has been removed."))
예제 #5
0
 async def del_notification(self, ctx: SlashContext, twitch_name: str):
     try:
         item = self.backend.get(TwitchWatchedUser,
                                 {'twitch_name': twitch_name})
     except TwitchWatchedUser.DoesNotExist:
         await ctx.send(embed=mkembed(
             "error", f"No notification exists for {twitch_name}"))
         return
     self.hook.unsubscribe(item['uuid'])
     self.bot.logger.info(f"Removing watch {item['uuid']}: {twitch_name}")
     self.backend.delete(item)
     if item['uuid'] in self.uuids:
         self.uuids.remove(item['uuid'])
     await ctx.send(
         embed=mkembed("done", f"Notification for {twitch_name} removed."))
예제 #6
0
 async def add_notification(self, ctx: SlashContext, twitch_name: str,
                            notify_channel: discord.TextChannel,
                            notify_text: str):
     twitch_id = self._login_to_id(twitch_name)
     try:
         self.backend.get(TwitchWatchedUser, {'twitch_name': twitch_name})
     except TwitchWatchedUser.DoesNotExist:
         pass
     except TwitchWatchedUser.MultipleDocumentsReturned:
         self.bot.logger.error(
             "Multiple users returned - database inconsistent???")
         return
     if not twitch_id:
         await ctx.send(embed=mkembed(
             'error',
             f"Unable to get the Twitch ID for the name {twitch_name}"))
         return
     await ctx.defer()  # This bit can take a minute.
     success, uuid = self.hook.subscribe_stream_changed(
         twitch_id, self._cb_stream_changed)
     if success and uuid:
         self.uuids.append(uuid)
         self.bot.logger.info(
             f"{success}: registered subscription UUID: {uuid}")
     else:
         self.bot.logger.error(
             f"{success}: failed registering subscription: {uuid}")
         await ctx.send("Bluh, couldn't register the webhook with twitch :("
                        )
         return
     item = TwitchWatchedUser({
         'twitch_name': twitch_name,
         'twitch_id': twitch_id,
         'discord_name': ctx.author.id,
         'notify_channel': notify_channel.id,
         'notify_text': notify_text,
         'uuid': str(uuid)
     })
     self.bot.logger.debug(f"DB object dump: {item.__dict__}")
     self.backend.save(item)
     await ctx.send(embed=mkembed("done",
                                  f"Notification added for {twitch_name}",
                                  channel=notify_channel.name))
예제 #7
0
 async def limitchannel(self, ctx: SlashContext, respond_to: str, **kwargs):
     comm = self._find_one(respond_to)
     if not comm:
         await ctx.send(embed=mkembed('error', f"'{respond_to}' does not exist."))
         return
     if not ctx.author.id == comm['creator_id']:
         await ctx.send(
             embed=mkembed('error', f"You are not the creator of '{respond_to}'. Ask {comm['creator_str']}"))
         return
     if len(kwargs) == 0:
         comm["restrictions"] = {}
         self.backend.save(comm)
         await ctx.send(embed=mkembed('done', f"All restrictions removed from {respond_to}"))
         return
     if kwargs['restrict_user']:
         if not comm.get("restrictions"):
             comm["restrictions"] = {}
         elif not comm["restrictions"].get("users"):
             comm["restrictions"]["users"] = []
         comm["restrictions"]["users"] = list(set(
             comm["restrictions"]["users"] + [u.id for u in restrict_user]
         ))
         self.backend.save(comm)
         display_users = [self.bot.get_user(u).display_name for u in comm["restrictions"]["users"]]
         await ctx.send(
             embed=mkembed('done', 'User restriction updated:', command=comm['command'], users=display_users)
         )
     if kwargs['restrict_channel']:
         if not comm.get("restrictions"):
             comm["restrictions"] = {}
         if not comm["restrictions"].get("channels"):
             comm["restrictions"]["channels"] = []
         comm["restrictions"]["channels"] = list(set(
             comm["restrictions"]["channels"] + [c.id for c in ctx.message.channel_mentions]
         ))
         display_channels = [self.bot.get_channel(c).name for c in comm["restrictions"]["channels"]]
         self.backend.save(comm)
         await ctx.send(
             embed=mkembed('done', 'Channel restriction updated:',
                           Command=comm['command'],
                           Channels=display_channels
                           )
         )
예제 #8
0
 async def addresponse(self, ctx: context, name: str, *responsen):
     """Adds an automatic response to (name) as (response)
     The first word (name) is the text that will be replied to. Everything else is what it will be replied to with.
     If you want to reply to an entire phrase, enclose name in quotes."""
     arg2 = " ".join(responsen)
     if self._find_one(name):
         await ctx.send(embed=mkembed('error', f"'{name}' already exists."))
         return
     else:
         comm = ResponseCommand({
             'command': name,
             'reply': arg2,
             'creator_str': str(ctx.author),
             'creator_id': ctx.author.id
         })
         self.backend.save(comm)
         self.bot.logger.info(
             f"'{name}' was added by {ctx.author.display_name}")
         await ctx.send(embed=mkembed('done', f"Saved: {name} => {arg2}"))