Пример #1
0
    async def santa(self, context):
        if not ss_season:
            await context.message.channel.send(
                "Hey " + get_rsn(context.message.author.mention) +
                ", it's not the season for that event!")

        player_rsn = get_rsn(
            context.message.author.mention)  # gets RSN of command user

        ss_entered = open('secret_santa.txt', 'r')  # opens secret santa roster
        ss_entries = ss_entered.read()  # reads roster
        ss_entered.close()  # closes roster

        if player_rsn is None:  # if RSN hasn't been set inform user
            await context.message.channel.send(
                "Hey " + context.message.author.mention +
                ", you have'nt set your RSN. \n"
                "Please set it with ::setrsn <name>.")
            return
        elif player_rsn in ss_entries:  # checks if user is already in secret santa
            await context.message.channel.send(
                "You've already entered the Secret Santa event " + player_rsn +
                "!")
            return

        ss_list = open('secret_santa.txt',
                       'a')  # opens secret santa roster in append mode
        ss_list.write(player_rsn + "\n")  # adds new user to roster
        ss_list.close()  # closes roster
        await context.message.channel.send(
            context.message.author.mention +
            " has joined the Secret Santa event!"
        )  # informs user that they have registered for Secret Santa
Пример #2
0
    async def eight_ball(self, context):
        user = context.message.author.mention  # sets user to the mention of the message author
        user = re.sub("<|>|!|@", "", user)  # removes extraneous characters from user ID

        player_rsn = get_rsn(user)  # gets the rsn of the user
        if player_rsn is None:  # checks if player has not set RSN
            await context.message.channel.send("I noticed you haven't yet set your RSN, you can do so by doing ::setrsn <name>.\n")

        elif player_rsn.lower() == 'malnec' or player_rsn.lower() == 'no wait nvm':  # checks if messenger is Malnec or Ace
            possible_responses = [
                'Please DONT do that',
                '8ball machine broke',
                'Ask someone else',
            ]
            await context.message.channel.send(random.choice(
                possible_responses) + ", " + context.message.author.mention)  # picks a random option and sends it back to command user
        elif player_rsn is not None:
            possible_responses = [
                'That is a resounding no',
                'It is not looking likely',
                'Too hard to tell',
                'It is quite possible',
                'Definitely',
                'What are you, a cop',
                "I don't feel comfortable answering that",
                'Why are you even asking, its obviously a yes',
                'Just no'
            ]
            await context.message.channel.send(random.choice(
                possible_responses) + ", " + context.message.author.mention)  # picks a random option and sends it back to command user
Пример #3
0
    async def stats(self, context):
        argv = context.message.content[8:]

        if len(argv) < 2:  #did user not provide a name? look up self.
            rsn = get_rsn(context.message.author.mention)
            player = runescapeapi.Highscores(rsn)

        else:  #if user did provide a name
            rsn = argv
            print(rsn)
            argv.replace(" ", "%20")
            player = runescapeapi.Highscores(argv)

        stat_list = parse_stats(player.skills)
        total_level = parse_total(player.total)

        stat_line = "```\n------------------------------------------------\n"
        title = "|" + "{:^46}".format(" Stats for " + rsn + " ") + "|"

        stat_line += title + "\n" + "|----------------------------------------------|\n"
        stat_line += "| {:^13} | {:>5} | {:>10} | {:>7} |".format(
            "Skill", "Level", "XP", "Rank") + "\n"
        stat_line += "|----------------------------------------------|\n"

        for stat in stat_list:
            stat_line = stat_line + stat + "\n"

        stat_line += total_level
        stat_line += "\n------------------------------------------------```"
        await context.message.channel.send(stat_line)

        print(total_level)
Пример #4
0
    async def checkrsn(self, context):
        player_rsn = get_rsn(
            context.message.author.mention)  # gets RSN of user

        if player_rsn is None:  # checks if name is not set
            await context.message.channel.send(
                "You have not set your RSN yet " +
                context.message.author.mention)
        else:  # prints saved RSN
            await context.message.channel.send("Your RSN is set to " +
                                               player_rsn + ".")
Пример #5
0
    async def updatersn(self, context):
        message = context.message.content
        if (len(message) < 13):
            await context.message.channel.send("Usage: ::updatersn <new name>")
            return

        users = open('users.txt', 'r')  # opens user file
        all_users = users.read()  # reads in users
        users.close()  # closes user file

        name = message[12:]  # gets new RSN to be set from message
        pairs = all_users.split("\n")  # splits users into array

        user = context.message.author.mention  # gets user mention of author
        user = re.sub("<|>|!|@", "", user)

        if get_rsn(user) is None:
            await context.message.channel.send(
                "Hey " + context.message.author.mention +
                ", you haven't set your RSN yet."
                "You can set it with ::setrsn <name>")
        elif get_user(context, name) is None:  # checks if RSN is taken
            for idx, a in enumerate(
                    pairs
            ):  # runs through user list and modifies appropriate user
                if user in pairs[idx]:
                    pairs[idx] = user + ":" + name

            rewrite_users = open('users.txt', 'w')  # opens user list
            for idx, a in enumerate(pairs):
                rewrite_users.write(pairs[idx] +
                                    "\n")  # rewrites user list to file
            rewrite_users.close()  # closes user file
            await context.message.channel.send(
                context.message.author.mention + " has changed their RSN to " +
                name + "."
            )  # responds to user to let them know their name has been updated
        elif get_user(context, name) == user:
            await context.message.channel.send(
                "You have already claimed the name " + name + ".")
        elif get_user(context, name) is not None:
            await context.message.channel.send(
                "The username " + name +
                " has been claimed. Please contact an Admin for help."
            )  # lets user know requested RSN is claimed.
Пример #6
0
    async def setrsn(self, context):
        message = context.message.content
        if len(message) < 9:
            await context.message.channel.send("Usage: ::setrsn <name>")
            return
        if '<' in message:
            await context.message.channel.send(
                "Please do not include brackets when setting your RSN. For example, do ::setrsn Faith"
            )
            return

        name = message[9:]  # parses RSN to be set from message
        user = context.message.author.mention  # gets mention of user
        user = re.sub("<|>|!|@", "",
                      user)  # strips extraneous characters from user ID

        if get_user(context, name) is not None:  # if the RSN has been claimed
            await context.message.channel.send(
                "The username " + name +
                " has been claimed. Please contact an Admin for help.")
        elif get_rsn(user) is not None:  # if the user has claimed a name
            await context.message.channel.send(
                "You have already claimed a name. Please use ::updatersn <name>"
            )
        else:  # user hasn't claimed a name and name is not taken
            aff = open('users.txt', 'a')  # opens user file as append

            combo = user + ":" + name  # stores user ID and RSN combo as string
            aff.write(combo + "\n")  # writes user ID and RSN combo to file
            aff.close()  # closes the user file

            await context.message.channel.send(
                context.message.author.mention + " has claimed the RSN " +
                name + "."
            )  # responds to user letting them know their name has been set

        await self.client.send_message(
            context.message.channel.server.owner,
            "User " + context.message.author.mention +
            " has tried to claim the RSN " + name)
Пример #7
0
    async def launch_santa(self, context):
        """
        Quick note about Discord user mentions before you read this function:
        Discord users all have a unique ID that can be used to mention them as if you were to @ their name.
        I'll call this the user mention. It looks something like this: <@162606971705491458> or <@!179067358369939456>
        Your user mention may or may not have an '!' as it's third character. This is dynamic as far as I know.
        Because of this, user-rsn pairs are saved by the bot based on your ID number, not the extraneous symbols.
        When creating SENDER_LIST, the bot looks up users based on their mention. There is a check in there that removes the
        extra '!' if the user does not have one in their mention
        """

        user_roles = context.message.author.roles  # gets user role list
        for role in user_roles:  # loops through user roles
            if '🗝️ FiH Leader' == role.name:  # checks if user has role to use command
                santa_file = open('secret_santa.txt',
                                  'r')  # opens secret santa roster
                participants = santa_file.read(
                )  # reads in participant list (set of RSNs)
                santa_file.close()  # closes secret santa roster

                participant_list = participants.split(
                    '\n')  # splits participants into list
                participant_users = []  # creates user array

                for p in participant_list:  # loops through participant list
                    user = get_user(
                        p)  # gets the user associated with given RSN
                    if user is not None:  # checks if RSN has been claimed by a user
                        participant_users.append(
                            user)  # adds user to participant list

                JAYCOLE = find(lambda m: m.mention == get_user("Jaycole"),
                               context.message.channel.server.members
                               )  # stores info for me for testing purposes
                if JAYCOLE is None:  # check if it used the wrong mention
                    j_user = get_user("Jaycole")  # gets my user mention again
                    j_user = re.sub("!", "", j_user)  # removes ! from mention
                    JAYCOLE = find(
                        lambda m: m.mention == j_user,
                        context.message.channel.server.members)  # re-saves me

                SENDER_LIST = [
                ]  # initialize sender list, which will be an array of Members

                # Member is a subclass of User, member is a Member
                # participant_users is an array of mentions

                for p in participant_users:  # loop through participants
                    member = find(
                        lambda m: m.mention == p,
                        context.message.channel.server.members
                    )  # find the person's User based on their mention
                    if member is None:  # checks if it used the wrong mention
                        p = re.sub("!", "", p)  # removes ! from mention
                        member = find(
                            lambda m: m.mention == p,
                            context.message.channel.server.members
                        )  # re checks for User based on new mention
                    SENDER_LIST.append(member)  # adds user to sender list

                receivers = participant_list  # stores receivers as a pointer to participant list so I don't have to read in twice.

                f = open("santa_log.txt", "w+")  # opens log file

                for user in SENDER_LIST:
                    s = random.uniform(0, receivers.__len__(
                    ))  # gets random value within list bounds
                    s = round(s)  # rounds random number to a usable index
                    receiver = receivers[s - 1]  # gets receiver at that index

                    while receiver == get_rsn(
                            user.mention
                    ) and receiver is not None:  # redraws if user gets themself or an error
                        s = random.uniform(0, receivers.__len__())
                        s = round(s)
                        receiver = receivers[s - 1]

                    receivers.pop(s - 1)  # removes receiver from list
                    try:  # tries to send target to user
                        await self.client.send_message(
                            user, "Hey " + get_rsn(user.mention) +
                            ", Your secret santa target is " + receiver + "!")
                    except:  # catches if user private messages are set to private, sends target to me
                        await self.client.send_message(
                            JAYCOLE, "Hey " + get_rsn(user.mention) +
                            ", your secret santa target is " + receiver + "!")

                    # await client.send_message(JAYCOLE, "Hey " + get_rsn(user.mention) + ", your secret santa target is " + receiver + "!") - test line to send all targets to me to test function
                    f.write((user.name + " got " + receiver +
                             '\n'))  # writes matches to log

                    time.sleep(
                        1
                    )  # waits one second to avoid overrunning action limits

                f.close()  # closes santa log
                await context.message.channel.send(
                    "Secret Santa targets have been sent out! Check your inbox for your person!"
                )  # announces that santa targets have been sent.
Пример #8
0
    async def alog(self, context):
        argv = context.message.content[7:]
        if len(argv) < 2:
            alog_docs = open("alog_docs.txt", 'r')
            alog_help = alog_docs.read()
            alog_docs.close()
            await context.message.channel.send(alog_help)
            return

        args = argv.split(' ')
        rsn = get_rsn(context.message.author.mention)

        if rsn is None:
            await context.message.channel.send(
                "Hey " + context.message.author.mention +
                ", you haven't set your RSN yet. Set it with ::setrsn")
            return

        if args[0] == 'activate':
            user_tracking = active_tracking(rsn)
            if user_tracking is True:
                await context.message.channel.send(
                    "User " + rsn + " added to active tracking roster.")
            else:
                await context.message.channel.send(
                    "I'm already keeping track of your adventurer log " + rsn)
        elif args[0] == 'track':
            await context.message.channel.send(
                track(self.client, context.message.channel, rsn))
        elif args[0] == 'drops':
            await context.message.channel.send("Getting drops for " + rsn)
            await context.message.channel.send(pull_drops(rsn))
        elif args[0] == 'xp':
            await context.message.channel.send("Getting XP milestones for " +
                                               rsn)
            await context.message.channel.send(pull_xp(rsn))
        elif args[0] == 'full':
            alog = (pull_alog(rsn))
            log = alog.split('\n')
            max = 10
            n = 0
            line = ""
            #items = [log[i:i + n] for i in range(0, len(log), n)]
            for item in log:
                line += item + '\n'
                n += 1
                if n == max:
                    await context.message.author.send(line)
                    line = ""
                    n = 0
                    time.sleep(2)

            await context.message.channel.send(
                "Check your private messages to see your full Adventurer's Log"
            )
        elif args[0] == 'help':
            alog_docs = open("alog_docs.txt", 'r')
            alog_help = alog_docs.read()
            alog_docs.close()
            await context.message.channel.send(alog_help)
            return
        elif args[0] == 'reset':
            await context.message.channel.send("Resetting logs for " + rsn)
            reset_user(rsn)
        else:
            await context.message.channel.send("Command not recognized.")
Пример #9
0
 async def hello(self, context):
     player_rsn = get_rsn(context.message.author.mention)  # gets RSN of user
     if player_rsn is None:  # checks if RSN has been set
         await context.message.channel.send("Hello " + context.message.author.mention + "!")  # says hello to user using their mention
     else:
         await context.message.channel.send("Hello " + player_rsn + "!")  # says hello to user using their RSN