-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_wingman.py
142 lines (108 loc) · 5 KB
/
main_wingman.py
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import discord
import asyncio
import datetime
import math
from wingman import Wingman
class MainWingman(Wingman):
timer_time = None
is_active = {}
extra_wingmen = []
def __init__(self, extra_wingmen):
super().__init__(1)
MainWingman.extra_wingmen = extra_wingmen
async def on_message(self, message):
if message.author == self.user or not message.content.startswith("$wingman"):
return
if message.guild.id not in self.is_available:
self.is_available[message.guild.id] = True
self.is_active[message.guild.id] = False
for extra_wingman in self.extra_wingmen:
if message.guild.id not in extra_wingman.is_available:
extra_wingman.is_available[message.guild.id] = True
if self.is_active[message.guild.id]:
return
command = message.content[9:]
if command in ["$w", "$h", "$m", "$wg", "$hg", "$mg", "$wa", "$ha", "$ma"]:
await self.roll_cmd(message, command)
elif "$give" in command:
await self.give_cmd(message, message.author, command)
elif "$del" in command:
await self.delete_cmd(message, command)
elif "$leaderboard" in command:
await message.channel.send((await self.get_channel(720106456724013128).history().get(author=self.user)).content)
async def on_reaction_add(self, reaction, user):
if not reaction.message.embeds or "Mudamaid" in user.name or "Mudae" in user.name:
return
if reaction.emoji not in ["❤️", "♥️", "💖", "💘", "💓", "💗", "💕"]:
return
for i in range(2, 7):
if user.name == "TripleFury" + str(i):
return
self.loop.create_task(self.claim_cmd(reaction, user))
# stop adding tasks after adding the first one
async def delete_cmd(self, message, command):
try:
print(self.prefix + "Deleting " + command[5:] + " messages for " + message.author.name)
await message.channel.purge(limit=int(command[5:]) + 1)
except discord.Forbidden:
print(self.prefix + "Forbidden")
async def claim_cmd(self, reaction, user):
def check(message):
return "married" in message.content and user.name in message.content
try:
await self.wait_for("message", timeout=5, check=check)
except asyncio.TimeoutError: # Claimed Unsuccessfully
for extra_wingman in self.extra_wingmen:
if await extra_wingman.claim(reaction.message, reaction, user):
break
async def give_cmd(self, message, user, command):
for extra_wingman in self.extra_wingmen:
if await extra_wingman.give(message, user, command):
break
async def roll_cmd(self, message, command):
guild_id = message.guild.id
self.is_active[guild_id] = True
if self.is_available[guild_id]:
await message.channel.send("Have no fear **" + message.author.name + "**, The Waifu Wingmen are here to grant you more rolls!")
await asyncio.sleep(1)
helped = False
for extra_wingman in self.extra_wingmen:
if extra_wingman.is_available[guild_id] and extra_wingman.get_guild(guild_id) is not None:
if await extra_wingman.roll(message, command):
helped = True
break
if not helped:
await asyncio.sleep(1)
minutes_left = self.timer_time - datetime.datetime.now()
await message.channel.send("Sorry, looks like all of the wingmen are unavailable 💔. Please try again in **" + str(math.ceil(minutes_left.seconds / 60)) + "** minutes.")
self.is_active[guild_id] = False
async def add_leaderboard(self, user):
leaderboard_channel = self.get_channel(720106456724013128)
message = await leaderboard_channel.history().get(author=self.user)
message_lines = message.content.splitlines()
leaders = {}
for line in message_lines:
if ")" in line:
line_split = line.split(":")
leaders[line_split[0].split(") ")[1]] = int(line_split[1])
if user.name in leaders:
leaders[user.name] += 1
else:
leaders[user.name] = 1
sorted_leaders = {}
for i in sorted(leaders, key=leaders.get, reverse=True):
sorted_leaders[i] = leaders[i]
leaders = sorted_leaders
total = 0
for leader in leaders:
total += leaders[leader]
final = "**Total Wingman Rolls**: `" + str(total) + "` ```\n"
i = 0
for leader in leaders:
i += 1
final += "{}) {}: {}\n".format(i, leader, str(leaders[leader]))
final += "```"
await message.edit(content=final)
leaderboard_channel = self.get_channel(720802906814808164)
message = await leaderboard_channel.history().get(author=self.user)
await message.edit(content=final)