summaryrefslogtreecommitdiff
path: root/cogs/OutstandingNeighbor.py
blob: 0d92121a9ac5aee49ddbe796c3eef234edc02b4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from discord.ext import commands
import discord
import re
import operator
colours = {"default": 0,
           "teal": 0x1abc9c,
           "dark teal": 0x11806a,
           "green": 0x2ecc71,
           "dark green": 0x1f8b4c,
           "blue": 0x3498db,
           "dark blue": 0x206694,
           "purple": 0x9b59b6,
           "dark purple": 0x71368a,
           "magenta": 0xe91e63,
           "dark magenta": 0xad1457,
           "gold": 0xf1c40f,
           "dark gold": 0xc27c0e,
           "orange": 0xe67e22,
           "dark orange": 0xa84300,
           "red": 0xe74c3c,
           "dark red": 0x992d22,
           "lighter grey": 0x95a5a6,
           "dark grey": 0x607d8b,
           "light grey": 0x979c9f,
           "darker grey": 0x546e7a,
           "blurple": 0x7289da,
           "greyple": 0x99aab5}


class OutstandingNeighbor(commands.Cog):
    def __init__(self, bot):
        self.bot = bot
        global extension_name
        extension_name = "[Outstanding Neighbor] "

    @commands.command(pass_context=True, hidden=True)
    async def on(self, ctx, *arg):
        """Release your anger and flip everything."""
        # Purge comment code
        str_cnl = self.bot.get_channel(451575153185390643)
        lst_users = {}
        int_vote_count = 0

        async for message_scan in str_cnl.history(limit=100, before=None, after=None):
            if not message_scan.pinned:
                str_msg = await str_cnl.fetch_message(message_scan.id)

                msg_string = re.search(r'@!?[0-9]{15,20}', str_msg.content)
                if msg_string is None:
                    continue
                msg_string = str(re.search(r'[0-9]{15,20}', str(msg_string)).group())

                obj_user = self.bot.get_user(int(msg_string))

                if len(arg) > 0 and arg[0] == obj_user.name:
                    continue

                try:
                    lst_users[obj_user.name] = int(lst_users[obj_user.name]) + 1
                except Exception as e:
                    lst_users[obj_user.name] = 1
                int_vote_count = int_vote_count + 1

        lst_users_sorted = sorted(lst_users.items(), key=operator.itemgetter(1), reverse=True)

        str_msg = "```"
        # intTotal = len(lst_users_sorted)

        for item in lst_users_sorted:
            str_count = str(item[1])
            str_name = str(item[0])
            int_percent = round((item[1] * 100) / int_vote_count, 2)
            str_percent = str(int_percent) + "%"
            while len(str_percent) < 6:
                str_percent = str_percent + " "

            str_msg = str_msg + str_count + " | " + str_percent + " | " + str_name + "\r\n"

        str_msg = str_msg + "Total: " + str(int_vote_count) + "\r\n"

        str_msg = str_msg+"```"
        await ctx.send(str_msg)

    @commands.command()
    async def site(self, ctx):
        await ctx.send(content="http://streamneighborhood.com")


def setup(bot):
    print("INFO: Loading [OutstandingNeighbor]... ", end="")
    bot.add_cog(OutstandingNeighbor(bot))
    print("Done!")


def teardown(bot):
    print("INFO: Unloading [OutstandingNeighbor]")