This repository has been archived by the owner on Sep 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
286 lines (238 loc) · 12.1 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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
import asyncio
import discord
import os
import random
import pytz
from discord.ext import commands, tasks
from discord.ext.commands import has_permissions
from itertools import cycle
from threading import Thread
import time
from datetime import datetime, date, timedelta
client = commands.Bot(command_prefix='.',
intents=discord.Intents.all())
client.remove_command('help')
status = cycle([
'cookie nomming', 'sleeping', 'being a ball of fluff', 'wheel running',
'tunnel digging', 'wires nibbling', 'food stashing', 'treasure burying',
'grand adventure', 'collecting taxes'
])
for filename in os.listdir('./util'):
if filename.endswith('.py'):
client.load_extension(f'util.{filename[:-3]}')
for filename in os.listdir('./cogs'):
if filename.endswith('.py'):
client.load_extension(f'cogs.{filename[:-3]}')
loop = asyncio.get_event_loop()
servers = client.get_cog('ServerManage')
@client.event
async def on_ready():
change_status.start()
print("Nibbles is awake!")
_thread = Thread(target=launch_tasks)
_thread.start()
def launch_tasks():
asyncio.set_event_loop(client.loop)
now = pytz.utc.localize(datetime.utcnow()).astimezone(pytz.timezone("America/Chicago"))
midnight = datetime.combine(date.today() + timedelta(days=1), datetime.min.time()) + timedelta(hours=6)
midnight = midnight.astimezone(pytz.timezone("America/Chicago"))
tdelta = midnight - now
midnight_time = tdelta.total_seconds() % (24 * 3600)
time.sleep(midnight_time)
announcement_manager.start()
async def announce_year_progress(channels):
tdelta = datetime.today() - datetime(datetime.today().year, 1, 1)
percent = (float(tdelta.days) / 365)
whole = int(percent * 15)
partial = int(percent * 90) % 6
empty = 15 - whole - partial
braille = {
0: '',
1: '⣄',
2: '⣆',
3: '⣇',
4: '⣧',
5: '⣷',
6: '⣿'
}
partial = braille[partial]
year_progress = f'[{(whole * "⣿")}{partial}{(empty * "⣀")}]'
for channel in channels:
await channel.send(f'{datetime.today().year} Progress Bar: \n{year_progress} {(percent * 100):.2f}%')
@tasks.loop(hours=24)
async def announcement_manager():
# wheel
await client.get_cog('Gamble').announce_wheel(await servers.wheel_channels())
# genshin_banner
await client.get_cog('Summon').new_banner_rotation(await servers.banner_channels())
# year_progress
await announce_year_progress(await servers.year_progress_channels())
# birthday
birthdays = servers.birthday_channels()
for birthday in birthdays:
await client.get_cog('Summon').birthday(birthday[0], birthday[1])
@tasks.loop(minutes=random.randrange(10, 45))
async def change_status():
await client.change_presence(activity=discord.Streaming(
name=next(status), url='https://twitch.tv/bitnoms'))
@client.event
async def on_member_join(member):
channel = servers.greetings_channel(member.guild.id)
if channel is None:
return
await channel.send(
f'Haii {member.name}, '
f'I\'m nibbles and welcome to the server! <:kayaya:778399319803035699>')
if member.guild.id == 607298393370394625:
await member.add_roles(discord.utils.get(member.guild.roles, name='Moons'))
await member.edit(nick=member.name.lower())
@client.event
async def on_member_remove(member):
channel = servers.greetings_channel(member.guild.id)
if channel is not None:
await channel.send(f'Bai bai {member.name} <:qiqi:813767632904781915>')
@client.event
async def on_command_error(ctx, error):
if '.transfer' in ctx.message.content:
return
if isinstance(error, commands.MissingRequiredArgument):
await ctx.send("nibbles can't do anything, something is missing! <:ShibaNervous:703366029425901620>")
elif isinstance(error, commands.CommandNotFound):
pass
else:
channel = await client.fetch_channel(819271204468031508)
await channel.send(f'[{datetime.now().strftime("%m/%d/%Y, %H:%M:%S")}] {error}\n')
@client.event
async def on_guild_join(guild):
await guild.owner.send("Haiii I'm nibbles, I am happy to meet you <a:ChikaYay:846769277944332319>")
await guild.owner.send("Set up for nibbles is ez! There are numerous things that nibbles can do, use the command "
".settings and .help in a channel you would want nibbles to be in to start!")
await guild.owner.send("If you run into any issues, you could always join the support server "
"linked in .help and ask ʙɪᴛ#5595!")
return
utility = ['choose', 'poll', 'get_pfp', 'size', 'profile', 'set_desc', 'set_birthday']
genshin = ['banner', 'event_wish', 'reg_wish', 'genshin_inventory', 'genshin_character', 'genshin_gift', 'pity',
'quick_sell']
anime = ['anime_list', 'anime_list_add', 'anime_list_remove', 'anime_inventory', 'anime_search', 'anime_character',
'anime_character_kick', 'anime_gift', 'wish_list', 'wish_list_add', 'wish_list_remove', 'wish_list_clear']
economy = ['gamble_black_jack', 'gamble_coin', 'gamble_rock_paper_scissors', 'bal', 'transfer']
leaderboard = ['leaderboard', 'rank']
todo = ['todo_list', 'todo_add', 'todo_check']
mod = ['purge', 'settings']
@client.command(name='help', hidden=True)
async def descriptions(ctx):
desc = 'Here are the categories of nibbles\'s commands! React to the corresponding category to learn more!\n'
desc += 'Mention nibbles for an :8ball: response!\n'
desc += 'For more help, join [Nibble\'s training ground](https://discord.gg/hycRhPYNpP)'
embed = discord.Embed(title="Nibbles is here to help", color=random.randint(0, 0xFFFFFF), description=desc)
simplified_anime = ['anime_list', 'anime_inventory', 'anime_search', 'anime_character', 'anime_character_kick',
'anime_gift', 'wish_list']
embed.add_field(name='**Anime** <a:KannaEat:844266819430776924>', value=str(simplified_anime))
embed.add_field(name='**Genshin** <:genshin:849405822781227069>', value=str(genshin))
embed.add_field(name='**Economy** 💰', value=str(economy))
if ctx.guild.id == 607298393370394625:
embed.add_field(name='**Leaderboard** 🌟', value=str(leaderboard))
embed.add_field(name='**Utility** 🔧', value=str(utility))
embed.add_field(name='**To-do** ✅', value=str(todo))
if ctx.author.permissions_in(ctx.channel).manage_guild:
embed.add_field(name='**Moderation Tools** 🔨', value=str(mod))
help_msg = await ctx.send(content='Help menu', embed=embed)
await help_msg.add_reaction('<a:KannaEat:844266819430776924>')
await help_msg.add_reaction('<:genshin:849405822781227069>')
await help_msg.add_reaction('💰')
if ctx.guild.id == 607298393370394625:
await help_msg.add_reaction('🌟')
await help_msg.add_reaction('🔧')
await help_msg.add_reaction('✅')
if ctx.author.permissions_in(ctx.channel).manage_guild:
await help_msg.add_reaction('🔨')
@client.command(hidden=True)
@has_permissions(manage_guild=True)
async def mod_help(ctx):
output = ''
for command in client.commands:
if command.hidden:
output += command.name + '\n'
await ctx.send(output)
@client.command(hidden=True)
async def send_data(ctx):
directory = './data/'
for file in os.listdir(directory):
if file.endswith('.json') or file.endswith('.db'):
await ctx.send(file=discord.File(os.path.join(directory, file)))
await asyncio.sleep(5)
@client.event
async def on_message(message):
if message.reference is None and client.user.mentioned_in(message) and str(client.user.id) in message.content:
eight_ball = [
'Nibbles agree.', 'Yesssu!', 'Yes yes.', 'Nibbles approve.',
'You can bet nom noms on it.', 'Nibbles thinks that is correct.',
'Most likely.', 'Good good.', 'Ooooo wats dat?',
'My nom noms said yes.', 'Huh? What did you say?.',
'I\'m sleepy... ask later.', 'Its a secret hehe.',
'Mommy says stranger danger!.', 'Bit said he doesn\'t know.',
'Nibbles thinks that is wrong.', 'My nom noms said no.',
'Nibbles disagree.', 'Noooooo!', 'That is incorrect.'
]
await message.channel.send(f'{random.choice(eight_ball)}')
else:
await client.process_commands(message)
@client.event
async def on_reaction_add(reaction, user):
if reaction.message.content == 'Help menu' and not user.bot:
embed = discord.Embed.Empty
if reaction.emoji == '🔧':
embed = discord.Embed(title='Utility', description='All sorts of commands that might come in handy!')
for comm_name in utility:
embed.add_field(name=comm_name, value=help_embed_value(comm_name), inline=False)
elif str(reaction.emoji) == '<:genshin:849405822781227069>':
desc = 'Get started by wishing on either the daily rotating banner or the permanent banner.' \
'Use .we to wish on the event banner and .wr for the permanent banner. ' \
'Use the .banner command to see today\'s banner. '
embed = discord.Embed(title='Genshin', description='A Genshin gacha simulator!\n' + desc)
for comm_name in genshin:
embed.add_field(name=comm_name, value=help_embed_value(comm_name), inline=False)
elif str(reaction.emoji) == '<a:KannaEat:844266819430776924>':
embed = discord.Embed(title='Anime', description='Collect all your favorite waifus! To get started, '
'add some of your favorite animes to your anime list to '
'make characters appear in a designated channel. '
'A channel must have 10 unique animes shared among it\'s '
'active chatters in order to spawn characters')
for comm_name in anime:
embed.add_field(name=comm_name, value=help_embed_value(comm_name), inline=False)
elif reaction.emoji == '💰':
embed = discord.Embed(title='Economy', description="Nom noms wealth management and GAMBLING 🎰.")
for comm_name in economy:
embed.add_field(name=comm_name, value=help_embed_value(comm_name), inline=False)
elif reaction.emoji == '🌟':
embed = discord.Embed(title='Leaderboard', description="How active are you in Project Void?")
for comm_name in leaderboard:
embed.add_field(name=comm_name, value=help_embed_value(comm_name), inline=False)
elif reaction.emoji == '✅':
embed = discord.Embed(title='To-do List', description='Manage your task lists with nibbles!')
for comm_name in todo:
embed.add_field(name=comm_name, value=help_embed_value(comm_name), inline=False)
elif reaction.emoji == '🔨':
embed = discord.Embed(title='Moderation Tools', description='haha mods go <:BennetBonk:853419733776728064>')
for comm_name in mod:
embed.add_field(name=comm_name, value=help_embed_value(comm_name), inline=False)
await reaction.message.edit(embed=embed)
def help_embed_value(comm_name):
command = client.get_command(comm_name)
value = command.description
if len(command.aliases) != 0:
value += f"\n{'aliases' if len(command.aliases) > 1 else 'alias'}: {command.aliases}"
return value
@client.event
async def on_raw_reaction_add(payload):
if payload.message_id == 804860150195945493:
guild = await client.fetch_guild(payload.guild_id)
member = await guild.fetch_member(payload.user_id)
await member.add_roles(role)
@client.event
async def on_raw_reaction_remove(payload):
if payload.message_id == 804860150195945493:
guild = await client.fetch_guild(payload.guild_id)
member = await guild.fetch_member(payload.user_id)
await member.remove_roles(role)
client.run('NzM2MDEzNjQ1MDQ1MzAxMzAx.XxooHw.90H7LW32mCJIzmtVyZTQehjhfSE')