def check_mentions(api, keywords, since_id):
    global keyword
    logger.info("Retrieving mentions")
    new_since_id = since_id
    for tweet in tweepy.Cursor(api.mentions_timeline,
                               since_id=since_id).items():
        new_since_id = max(tweet.id, new_since_id)
        name = tweet.user.name
        uname = tweet.user.screen_name
        tweet_id = tweet.id
        if tweet.in_reply_to_status_id is not None:
            continue
        for keyword in keywords:
            if keyword in tweet.text.lower():
                print("Found keyword: " + keyword)
                reply = KEYWORDS[keyword]
                print("Found Reply:    " + reply)
                logger.info("Answering to " + tweet.user.name)
                text = "@" + tweet.user.screen_name
                tweet_text = text + " " + reply
                try:
                    api.update_status(
                        status=tweet_text,
                        in_reply_to_status_id=tweet.id,
                    )
                except tweepy.error.TweepError as e:
                    ErrorLog("[AUTO ERROR]" + str(e))
                    if MAIL:
                        sub = "[ERROR] {0}".format(name)
                        tweet_url = "https://twitter.com/{0}/status/{1}".format(
                            uname, tweet_id)
                        mess = tweet_url + "\n"
                        mess += str(e)
                        body = "{0} \n\nOccured at {1}".format(mess, timestr)
                        mail(sub, body)

                if FOLLOW:
                    if not tweet.user.following:
                        try:
                            tweet.user.follow()
                        except tweepy.error.TweepError as e:
                            ErrorLog("[AUTO ERROR]" + str(e))
                            if MAIL:
                                sub = "[ERROR] {0}".format(name)
                                tweet_url = "https://twitter.com/{0}/status/{1}".format(
                                    uname, tweet_id)
                                mess = tweet_url + "\n"
                                mess += str(e)
                                body = "{0} \n\nOccured at {1}".format(
                                    mess, timestr)
                                mail(sub, body)

    return new_since_id
Example #2
0
 async def vote_error(self, ctx, error):
     if isinstance(error, commands.CheckFailure):
         ConsoleMessage(f'{ctx.author} attempted to use .vote in #{ctx.channel}')
         await ctx.message.delete()
     else:
         ErrorLog(error)
         await ctx.message.delete()
Example #3
0
 async def changestatus_error(self, ctx, error):
     #if the error is due to lack of privileges, inform console
     if isinstance(error, commands.CheckFailure):
         ConsoleMessage(
             f'{ctx.author} failed to use .changestatus due to lack of privileges'
         )
     #otherwise, add errorlog
     else:
         ErrorLog(error)
Example #4
0
 async def rolemessage(self, ctx, *, msg):
     try:
         with open(f'{PATH}\\config\\roles.json', 'r') as f:
             data = json.load(f)
         data['message'] = msg
         with open(f'{PATH}\\config\\roles.json', 'w') as f:
             json.dump(data, f, indent=4)
         out = 'Message successfully changed!'
         ConsoleMessage(f'{ctx.author} changed the .rolemessage to "{msg}"')
     except Exception as e:
         ErrorLog(e)
     await ctx.send(out)
Example #5
0
 async def clear_error(self, ctx, error):
     #if the user does not have the required permissions, inform the console
     if isinstance(error, commands.CheckFailure):
         ConsoleMessage(
             f'{ctx.author} failed to use .clear due to lack of privileges')
     #otherwise, assume poor input
     elif isinstance(error, commands.BadArgument):
         randval = random.randint(2, 20)
         await ctx.send(
             f'Sorry {ctx.author.mention}, I don\'t think I understand. Try `.clear {randval}` to remove {randval} messages'
         )
     else:
         ErrorLog(error)
Example #6
0
    async def removerole(self, ctx, role):
        if role.startswith('<@&') and role.endswith('>') and len(role) == 22:
            role = role[3:]
            tmp = get(ctx.guild.roles, id=int(role[:-1]))
            if tmp != None:
                role = tmp.name
        found = False
        for react, rl in self.roleData.items():
            if role == rl:
                del self.roleData[react]
                found = True
                break
        if found:
            try:
                with open(f'{PATH}\\config\\roles.json', 'r') as f:
                    data = json.load(f)
                rolenames = list(self.roleData.values())
                reactnames = list(self.roleData.keys())
                data['roles'] = []
                for i in range(len(rolenames)):
                    data['roles'].append({
                        'role name': rolenames[i],
                        'reaction': reactnames[i]
                    })
                with open(f'{PATH}\\config\\roles.json', 'w') as f:
                    json.dump(data, f, indent=4)
                rl = get(ctx.guild.roles, name=role)
                if rl != None:
                    out = f'Successfully removed {rl.mention} from the self assigning list'
                else:
                    out = f'Successfully removed {role} from the self assigning list'
                ConsoleMessage(
                    f'{ctx.author} removed "{role}" as an assignable role')

            except Exception as e:
                ErrorLog(e)
        else:
            rl = get(ctx.guild.roles, name=role)
            if rl != None:
                out = f'I\'m sorry {ctx.author.mention} but the role {rl} doesn\'t appear to be assigned to anything'
                ConsoleMessage(
                    f'{ctx.author} attempted to remove {role}" as an assignable role but it does not appear to be on the list'
                )

            else:
                out = f'I\'m sorry {ctx.author.mention} but the role {role} doesn\'t appear to be assigned to anything'
                ConsoleMessage(
                    f'{ctx.author} attempted to remove {role}" as an assignable role but it does not appear to exist'
                )
        await ctx.send(out)
Example #7
0
 async def addrole(self, ctx, react, role):
     if react.startswith('<:') and react.endswith('>') and len(react) > 22:
         react = react.replace('<:', '')
         react = react[:-20]
     if role.startswith('<@&') and role.endswith('>') and len(role) == 22:
         role = role[3:]
         tmp = get(ctx.guild.roles, id=int(role[:-1]))
         if tmp != None:
             role = tmp.name
     out = ''
     rl = get(ctx.guild.roles, name=role)
     em = get(ctx.guild.emojis, name=react)
     if rl == None:
         out = f'I\'m sorry {ctx.author.mention} but I couldn\'t find a role called "{role}"'
     if em == None:
         if out == '':
             out = f'I\'m sorry {ctx.author.mention} but I couldn\'t find an emoji called ":{react}:".\nMake sure that the reaction is a custom emoji and not a default emoji'
         else:
             out += f' or an emoji called ":{react}:".\nMake sure that the reaction is a custom emoji and not a default emoji'
     elif out == '':
         try:
             exists = False
             tmprl = list(self.roleData.values())
             tmpem = list(self.roleData.keys())
             if role in tmprl:
                 exists = True
                 out = 'This role is already on the list for autoassign roles'
             elif react in tmpem:
                 rlnew = get(ctx.guild.roles, name=self.roleData[react])
                 if rlnew != None:
                     out = f'This reaction is already being used for the role {rlnew.mention}'
                     exists = True
             if exists == False:
                 try:
                     with open(f'{PATH}\\config\\roles.json', 'r') as f:
                         data = json.load(f)
                     data['roles'].append({
                         "role name": role,
                         "reaction": react
                     })
                     with open(f'{PATH}\\config\\roles.json', 'w') as f:
                         json.dump(data, f, indent=4)
                 except:
                     ConsoleMessage(
                         f'{ctx.author} used .addrole but file was missing.'
                     )
                     data = {
                         'message id': 0,
                         'channel id': 0,
                         'message':
                         'Hey @everyone!\nPlease react to this message if you would like access to other parts of the server with the reactions shown below! :smile:\n',
                         'roles': [{
                             "role name": role,
                             "reaction": react
                         }]
                     }
                     with open(f'{PATH}\\config\\roles.json', 'w') as f:
                         json.dump(data, f, indent=4)
                     ConsoleMessage(
                         'Missing file "config/roles.json" successfully generated'
                     )
                 out = f'Successfully added the role {rl.mention} to the reaction {em}'
                 ConsoleMessage(
                     f'{ctx.author} added "{role}" as an assignable role with reaction ":{react}:"'
                 )
                 self.roleData[react] = role
         except Exception as e:
             ErrorLog(e)
     await ctx.send(out)
Example #8
0
    async def autoroles(self, ctx):
        try:
            with open(f'{PATH}\\config\\roles.json', 'r') as f:
                data = json.load(f)
            roles = []
            reacts = []
            svrFound = False
            message = 'Hey @everyone!\nPlease react to this message if you would like access to other parts of the server with the reactions shown below! :smile:\n'
            if 'message' in data:
                message = data['message']
            else:
                data['message'] = message
            for rls in data['roles']:
                if 'role name' in rls and 'reaction' in rls:
                    roles.append(rls['role name'])
                    reacts.append(rls['reaction'])
                    svrFound = True
            if svrFound:
                for i in range(len(roles)):
                    emoji = get(ctx.guild.emojis, name=reacts[i])
                    role = get(ctx.guild.roles, name=roles[i])
                    if emoji != None and role != None:
                        message += f'\n{emoji} - {role.mention}'
                    else:
                        del roles[i]
                        del reacts[i]

                msg = await ctx.send(message)

                #attempts to delete old message with reacts
                try:
                    ch = self.client.get_channel(data['channel id'])
                    oldmsg = await ch.fetch_message(data['message id'])
                    await oldmsg.delete()
                except:
                    pass
                #saves new data
                data['channel id'] = ctx.channel.id
                data['message id'] = msg.id
                with open(f'{PATH}\\config\\roles.json', 'w') as f:
                    json.dump(data, f, indent=4)
                self.roleData = dict(zip(reacts, roles))
                self.messageID = msg.id
                await ctx.message.delete()
                for symb in reacts:
                    if symb != None:
                        await msg.add_reaction(get(ctx.guild.emojis,
                                                   name=symb))
            else:
                await ctx.send(
                    'There doesn\'t seem to be any roles to react to at the moment'
                )
        except:
            try:
                data = {
                    'message id': 0,
                    'channel id': 0,
                    'message':
                    'Hey @everyone!\nPlease react to this message if you would like access to other parts of the server with the reactions shown below! :smile:\n',
                    'roles': []
                }
                with open(f'{PATH}\\config\\roles.json', 'w') as f:
                    json.dump(data, f, indent=4)
                await ctx.send(
                    'There doesn\'t appear to be any role data avaliable at the moment. The file has been replaced with an example'
                )
            except Exception as e:
                ErrorLog(e)
Example #9
0
 async def endpoll_error(self,ctx,error):
     if isinstance(error, commands.CheckFailure):
         ConsoleMessage(f'{ctx.author} attempted to use .endpoll in #{ctx.channel}')
     else:
         ErrorLog(error)
Example #10
0
 async def rmvcmd_error(self, ctx, error):
     await ctx.send(
         f'You need to enter the name of the command after `.rmvcmd`')
     ErrorLog(error)
Example #11
0
 async def addcmd_error(self, ctx, error):
     await ctx.send(
         f'Sorry {ctx.author.mention}, but I think you inputted that command in wrong. Try adding a response after the command! :sweat_smile:'
     )
     ErrorLog(error)
Example #12
0
 async def stats_error(self, ctx, error):
     ErrorLog(error)
Example #13
0
 async def help2_error(self, ctx, error):
     ErrorLog(error)