-
Notifications
You must be signed in to change notification settings - Fork 2
/
bot.py
115 lines (82 loc) · 2.92 KB
/
bot.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
import discord
from discord.ext.commands import Bot
role_whitelist = [
182106535588134912, # US_South
182107305125347328, # South_America
182107632293773313, # Japan
182107963115175940, # Africa
182108089946734592, # Australasia
182108160117571585, # Southeast_Asia
182108273007263744, # Asia
182108333690454016, # Eastern_Europe
182108404091846656, # Western_Europe
182108484991582208, # UK_And_Ireland
182108603824472064, # Central_America
182108658853740544, # US_Northeast
182108743771750400, # US_Midwest
182108808313569280, # US_Southwest
182108858448084992, # US_Mountain_West
182108955613462528, # US_Pacific_Coast
182109068591235073, # Eastern_Canada
182109121150058496, # Western_Canada
]
role_match = {}
intents = discord.Intents.default()
silph_bot = Bot(intents=intents,command_prefix="!")
def build_roles(roles):
for r in roles:
if int(r.id) in role_whitelist:
role_match[r.name.lower()] = r
def get_role(ch):
name = str(ch).replace('#', '').lower()
return role_match.get(name)
@silph_bot.event
async def on_ready():
for s in silph_bot.guilds:
build_roles(s.roles)
await silph_bot.change_presence(activity=discord.Game(name='Pokemon Go'))
print("Bot is active")
@silph_bot.command(pass_context=True)
async def silphbot(ctx, channel):
channel_id = channel.replace('<#', '').replace('>', '')
name = ctx.message.guild.get_channel(int(channel_id))
if not name:
return
name = name.name
role = get_role(name)
if not role:
print("{} is not a role".format(name))
return
await ctx.message.author.add_roles(role)
await ctx.message.add_reaction(u"\U0001F44B")
print("{} joined {}".format(ctx.message.author, role.name))
@silph_bot.command(pass_context=True)
async def hello(ctx):
pass
# print(dir(ctx.message.author))
# return await silph_bot.say("Hello, world!")
@silph_bot.command(pass_context=True)
async def working(ctx, *, status: str):
if str(ctx.message.author.top_role) != 'Executives':
return
return await silph_bot.change_presence(game=discord.Game(name=status))
@silph_bot.command(pass_context=True)
async def map(ctx):
await ctx.send(
'The Silph League is a global player network for Pokemon GO that '
'enables large-scale coordination and events! You can view the map '
'of local groups here: https://thesilphroad.com/map'
)
@silph_bot.command(pass_context=True)
async def atlas(ctx):
await ctx.send(
'The Silph Atlas is a global community tool for reporting nests in Pokemon '
'Go. Check the map at : https://thesilphroad.com/atlas and report nests '
'around you !'
)
if __name__ == '__main__':
import os
token = os.environ.get('DISCORD_KEY')
if not token:
raise Exception('DISCORD_KEY is not set')
silph_bot.run(token)