Exemplo n.º 1
0
async def on_ready():
    guild = client.get_guild(utilities.get_guildID())
    role_name_to_obj = {
        role.name: {
            "name": role.name,
            "mention": role.mention
        }
        for role in guild.roles
    }
    key_name = ("test_" if os.getenv("mode") == "test" else "") + "study_roles"

    if os.getenv("mode") == "test":
        utilities.config["test_study_roles"] = copy.deepcopy(
            utilities.config["study_roles"])

    for key, val in utilities.config["study_roles"].items():
        print(role_name_to_obj[key])
        utilities.config[key_name][key]["name"] = role_name_to_obj[key]["name"]
        utilities.config[key_name][key]["mention"] = role_name_to_obj[key][
            "mention"]

    with open("config.hjson", "w") as f:
        hjson.dump(utilities.config, f)

    await client.logout()
Exemplo n.º 2
0
 async def fetch(self):
     if not self.guild:
         self.guild = self.bot.get_guild(utilities.get_guildID())
     self.role_name_to_obj = utilities.config[
         ("test_" if os.getenv("mode") == "test" else "") + "study_roles"]
     self.supporter_role = self.guild.get_role(
         utilities.config["other_roles"]
         [("test_" if os.getenv("mode") == "test" else "") + "supporter"])
Exemplo n.º 3
0
async def on_ready():
    guild = client.get_guild(utilities.get_guildID())
    role_names = list(config["study_roles"].keys())
    role_names.reverse()
    for role_name in role_names:
        await guild.create_role(name=role_name, hoist=True, mentionable=True)

    await client.logout()
Exemplo n.º 4
0
        def the_task(self, user_list, roles):
            count = 0
            countAddedRoles = 0
            countRemovedRoles = 0
            toUpdate = {
            }  # {discord.Member: {"add": [discord.Role], "remove": [discord.Role]} }

            # for each user in the list
            for user in user_list:
                count += 1

                # if the number of entries isn't two, then there is an error
                if len(user) != 2:
                    print("Invalid user tuple in user_list")
                    continue

                # get the member from the discord api by id
                m = self.client.get_guild(utilities.get_guildID()).get_member(
                    int(user[0]))

                # if user doesn't exist (potentially they left the server), continue
                if not m: continue

                # get the user's hours from redis
                hours = user[1]

                # for each role,
                # remove roles that the user should no longer hold
                # add roles that the user now holds
                for r in roles:
                    # min_ and max_ are the bounds for the role of interest
                    min_ = float(r["hours"].split("-")[0])
                    max_ = float(r["hours"].split("-")[1])
                    if min_ <= hours < max_ or (hours >= 350 and r["id"]
                                                == 676158518956654612):
                        if not m.guild.get_role(r["id"]) in m.roles:
                            # if user hours are inside the bounds for this role, and the user doesn't already have this role
                            # store that the role should be added to this user in the `toUpdate` object
                            if m not in toUpdate:
                                toUpdate[m] = {"add": [], "remove": []}
                            toUpdate[m]["add"].append(m.guild.get_role(
                                r["id"]))
                            countAddedRoles += 1
                    else:
                        if m.guild.get_role(r["id"]) in m.roles:
                            # if user hours are outside the bounds for this role, and the user has this role
                            # store that the role should be removed from this user in the `toUpdate` object
                            if m not in toUpdate:
                                toUpdate[m] = {"add": [], "remove": []}
                            toUpdate[m]["remove"].append(
                                m.guild.get_role(r["id"])
                            )  # await m.remove_roles(m.guild.get_role(r["id"]))
                            countRemovedRoles += 1

            # return the dict storing role update information
            return toUpdate
Exemplo n.º 5
0
 async def fetch(self):
     """
     Get discord server objects and info from its api
     Since it is only available after connecting, the bot will catch some initial commands but produce errors util this function is finished, which should be quick
     """
     if not self.guild:
         self.guild = self.bot.get_guild(utilities.get_guildID())
     self.role_name_to_obj = utilities.config[
         ("test_" if os.getenv("mode") == "test" else "") + "study_roles"]
     # supporter_role is a role for people who have denoted money
     self.supporter_role = self.guild.get_role(
         utilities.config["other_roles"]
         [("test_" if os.getenv("mode") == "test" else "") + "supporter"])
Exemplo n.º 6
0
async def on_ready():
    guild = client.get_guild(utilities.get_guildID())
    a = await main()
    res = a[0]
    for i in a[1:]:
        res = pd.merge(res, i, how="outer", on="Discord username")
    # Make ids string to prevent finite precision as Dataframe converts into to floats
    username_to_id = {member.name + "#" + member.discriminator: str(member.id) for member in guild.members}
    res["id"] = res["Discord username"].map(username_to_id)
    res.dropna(subset=["id"], inplace=True)
    res["id"] = res["id"].astype(int)
    res.to_csv("./user_files/user_stats.csv", index=False, float_format='{:f}'.format, encoding='utf-8')

    await client.logout()
Exemplo n.º 7
0
    async def fetch(self):
        """
        Get discord server objects and info from its api
        Since it is only available after connecting, the bot will catch some initial commands but produce errors until this function is finished, which should be quick
        """

        # set the guild of interest
        if not self.guild:
            self.guild = self.bot.get_guild(utilities.get_guildID())

        # get the relevant role names from the config file based on whether or not we are in test mode
        self.role_names = utilities.config[
            ("test_" if os.getenv("mode") == "test" else "") + "study_roles"]
        # supporter_role is a role for people who have denoted money
        self.supporter_role = utilities.config["other_roles"][
            ("test_" if os.getenv("mode") == "test" else "") + "supporter"]
async def on_ready():
    guild = client.get_guild(utilities.get_guildID())
    monitored_categories = dict()

    for category in guild.categories:
        if category.name[0] == "🔊" or category.name in ["staff", "STAFF"]:
            monitored_categories[category.name] = category.id

    key_name = ("test_" if os.getenv("mode") == "test" else
                "") + "monitored_categories"
    config[key_name] = monitored_categories

    with open("config.hjson", "w") as f:
        hjson.dump(config, f)

    await client.logout()