Exemple #1
0
 async def switch_db_toggle(self, ctx):
     """Toggle member's switch availability status in database."""
     author = ctx.author
     # Get current status
     db.execute('''SELECT switch FROM mentors WHERE discord_id = %(id)s''',
                {'id': author.id})
     current = db.fetchone()[0]
     # Toggle
     if current:
         new = False
         status = '- Unavailable'
     else:
         new = True
         status = '+ Available'
     db.execute(
         '''UPDATE mentors SET switch = %(new)s WHERE discord_id = %(id)s''',
         {
             'new': new,
             'id': author.id
         })
     conn.commit()
     # Send embed
     embed = discord.Embed(
         color=16711690,
         description=f'**{author.mention} {str(author)}:**\n'
         f'```diff\n{status}```',
         timestamp=datetime.utcnow())
     embed.set_author(name='Switch availability updated',
                      icon_url=author.avatar_url)
     embed.set_footer(text=f'ID: {author.id}')
     await ctx.send(embed=embed)
Exemple #2
0
def dnd_mentors(bot, character=None, region=None):
    """Return DND mentors of given character/region for embed."""
    mentors = []
    if character:
        db.execute(
            '''SELECT discord_id, name, region, switch, xbox FROM mentors WHERE
                   characters LIKE %(character)s AND do_not_disturb''',
            {'character': f'%{character}%'})
    elif region:
        db.execute(
            '''SELECT discord_id, name, characters, switch, xbox FROM mentors WHERE 
                   region = %(region)s AND do_not_disturb''',
            {'region': region})
    for row in db.fetchall():
        try:
            mentor = bot.get_user(row[0])  # discord_id
            mentors.append(f"{mentor.mention} **{str(mentor)}** ({row[2]})"
                           )  # character/region
        except AttributeError:  # catch if user ID isn't found, eg. left the server
            mentors.append(f"{row[1]} ({row[2]})")  # name, character/region
        # :switch:, :xbox: emotes next to names
        if row[3]:  # switch
            mentors[-1] += ' <:switch:759539694937309186>'
        if row[4]:  # xbox
            mentors[-1] += ' <:xbox:759539695553085460>'
    return '\n'.join(mentors)
Exemple #3
0
def teach_response(intent, response):
    execute(
        'INSERT INTO responses(intent, response) VALUES (?, ?) '
        'ON CONFLICT(intent) DO UPDATE SET response = ?',
        (intent, response, response))

    if intent not in intents.keys():
        intents[intent] = []
        client.add_intent(intent)
Exemple #4
0
def stop(team, channel_id, pattern):
    sql = """
    delete from clippingsbot.team_patterns
    where team_id = :team_id and channel_id = :channel_id
      and lower(display_pattern) = lower(:pattern)
    """
    db.execute(sql,
               team_id=team['team_id'],
               channel_id=channel_id,
               pattern=pattern)
Exemple #5
0
 async def advisor_role_toggle(self, ctx):
     """Toggle member's roles from mentor to advisor, and update database."""
     embed = await helpers.update_roles(
         ctx.guild.get_member(ctx.author.id),
         discord.utils.get(ctx.guild.roles, name='Mentor'),  # Remove
         discord.utils.get(ctx.guild.roles, name='Advisor'))  # Add
     # Update database
     db.execute(
         '''UPDATE mentors SET status = 'Advisor' WHERE discord_id = %(id)s''',
         {'id': ctx.author.id})
     conn.commit()
     await ctx.send(embed=embed)
Exemple #6
0
def watch(team, channel_id, pattern, pattern_id):
    sql = """
    insert into clippingsbot.team_patterns (
      team_id, channel_id, pattern_id, display_pattern
    )
    values (:team_id, :channel_id, :pattern_id, :pattern)
    on conflict (team_id, channel_id, pattern_id) do nothing
    """
    db.execute(sql,
               team_id=team['team_id'],
               channel_id=channel_id,
               pattern_id=pattern_id,
               pattern=pattern)
Exemple #7
0
def record(pending_notification):
    sql = """
    insert into clippingsbot.notifications (
      team_id, pattern_id, channel_id, feed, comments_url, link_url
    ) values (
      :team_id, :pattern_id, :channel_id, :feed, :comments_url, :link_url
    )
    on conflict (team_id, pattern_id, channel_id, feed, comments_url)
    do update set created = current_timestamp
    """
    db.execute(
        sql,
        team_id=pending_notification['team_id'],
        pattern_id=pending_notification['pattern_id'],
        channel_id=pending_notification['channel_id'],
        feed=pending_notification['feed'],
        link_url=pending_notification['link_url'],
        comments_url=pending_notification['comments_url'],
    )
Exemple #8
0
 async def do_not_disturb_toggle(self, ctx):
     """Toggle member's do not disturb role, and update database."""
     mentors_role = discord.utils.get(ctx.guild.roles, name='Mentors')
     dnd_role = discord.utils.get(ctx.guild.roles, name='DO NOT DISTURB')
     member = ctx.guild.get_member(ctx.author.id)
     # Mentors -> DND
     if mentors_role in ctx.author.roles:
         dnd_value = True
         # Change nickname
         try:
             if ctx.author.display_name[:6] != '[DND] ':
                 await ctx.author.edit(
                     nick=f'[DND] {ctx.author.display_name}')
         except discord.errors.Forbidden:
             pass
         # Update roles and get embed
         embed = await helpers.update_roles(member, mentors_role, dnd_role)
     # DND -> Mentors
     elif dnd_role in ctx.author.roles:
         dnd_value = False
         # Change nickname
         try:
             if ctx.author.display_name[6:] == ctx.author.name:
                 await ctx.author.edit(nick=None)
             elif ctx.author.display_name[:6] == '[DND] ':
                 await ctx.author.edit(nick=ctx.author.display_name[6:])
         except discord.errors.Forbidden:
             pass
         # Update roles and get embed
         embed = await helpers.update_roles(member, dnd_role, mentors_role)
     # Update database
     db.execute(
         '''UPDATE mentors SET do_not_disturb = %(value)s WHERE discord_id = %(id)s''',
         {
             'value': dnd_value,
             'id': ctx.author.id
         })
     conn.commit()
     await ctx.send(embed=embed)