-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
212 lines (159 loc) · 7.19 KB
/
main.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
import os
import discord
from dotenv import load_dotenv
from Helper import Player, players, Song
from bot import bot
from buttons import PlayerView
from db.Command import RecommandSongCommand
load_dotenv()
def p(a: any):
if os.getenv('ZEROTWO_VERSION') == 'develop':
print(a)
@bot.event
async def on_ready():
print('on_ready zerotwo!')
@bot.slash_command(name='dance', description='Dance zerotwo.')
async def dance(context: discord.ApplicationContext):
# For logging.
print('Command: dance')
print(f'who: {context.author.name}')
await context.respond('https://tenor.com/bHumN.gif')
@bot.slash_command(name='ping', description='Ping Pong 무한 Repeat!')
async def ping(context: discord.ApplicationContext):
# For logging.
print('Command: ping')
print(f'who: {context.author.name}')
await context.defer()
embed = discord.Embed(title='Ping Pong 무한 Repeat! 🏓')
if context.voice_client:
embed.add_field(name=f'Latency', value=f'`{bot.latency * 1000:.2f}`ms')
await context.respond(content='https://tenor.com/bI3bh.gif')
return await context.respond(embed=embed)
else:
embed.add_field(name='Error', value='I cannot get a valid latency :(')
return await context.respond(embed=embed)
@bot.slash_command(name='zerotwo',
description='Search keyword or Use URL. (To add more songs in queue, Just use this command)')
async def zerotwo(context: discord.ApplicationContext, url_or_keyword: str):
# For logging.
print('Command: play')
print(f'who: {context.author.name}')
print(f'message: {url_or_keyword}')
await context.defer()
if not context.author.voice:
return await context.respond(content='You have to join VC first!')
voice_channel = context.author.voice.channel
if not context.voice_client:
await voice_channel.connect()
else:
await context.voice_client.move_to(channel=voice_channel)
# Play the song!
try:
player = players.get(context.guild_id)
if not player and not hasattr(player, 'play_queue'):
p(f'creating player in players!')
player = Player(context)
players[context.guild_id] = player
view = PlayerView(context, player)
# Fetch first song of added to queue.
song = await players[context.guild_id].play(url_or_keyword, context.author.id)
if not song:
return await context.respond(content='cannot fetch song.')
embed = discord.Embed()
embed.add_field(name='Added to queue 🎧', value=f"[{song.title}]({song.webpage_url}) - {song.duration}")
embed.set_image(url=song.thumbnail_url)
return await context.respond(embed=embed, view=view)
except Exception as e:
await context.voice_client.disconnect(force=True)
if players.get(context.guild_id):
del players[context.guild_id]
return await context.respond(content=str(e))
@bot.slash_command(name='hey', description='Just say hey! 다시 위로 올라가기 귀찮을 때 불러보세요.')
async def hey(context: discord.ApplicationContext):
# For logging.
print('Command: hey')
print(f'who: {context.author.name}')
await context.defer()
if not context.author.voice:
return await context.respond(content='You have to join VC first!')
voice_channel = context.author.voice.channel
if not context.voice_client:
await voice_channel.connect()
else:
await context.voice_client.move_to(channel=voice_channel)
# Play the song!
try:
player = players.get(context.guild_id)
if not player and not hasattr(player, 'play_queue'):
p(f'creating player in players!')
player = Player(context)
players[context.guild_id] = player
view = PlayerView(context, player)
# Fetch first song of added to queue.
song: Song = await player.get_current_playing_song()
if not song:
return await context.respond(content='cannot fetch song.')
embed = discord.Embed()
embed.add_field(name='Current Playing Song 🎧', value=f"[{song.title}]({song.webpage_url}) - {song.duration}")
embed.set_image(url=song.thumbnail_url)
return await context.respond(embed=embed, view=view)
except Exception as e:
await context.voice_client.disconnect(force=True)
if players.get(context.guild_id):
del players[context.guild_id]
return await context.respond(content=str(e))
@bot.slash_command(name='recommand_song', description='Play recommand song by ZeroTwo_bot.')
async def recommand_song(context: discord.ApplicationContext, anything_to_tell: str):
# TODO: Connect with Llama-2
RecommandSongCommand.create(etc=anything_to_tell, user_id=context.author.id)
@bot.slash_command(name='force_quit', description='this require password')
async def force_quit(context: discord.ApplicationContext, password: str):
# For logging.
print('Command: force_quit')
print(f'who: {context.author.name}')
print(f'password: {password}')
if password == os.getenv('ZEROTWO_FORCE_RESTART_PWD', ''):
await context.respond('ZeroTwo_bot restarting')
return exit(-1)
else:
return await context.respond('password is not matched.')
@bot.slash_command(name='version', description='Check new features!')
async def version(context: discord.ApplicationContext):
# For logging.
print('Command: version')
print(f'who: {context.author.name}')
embed = discord.Embed(
title=f'Welcome to [ZeroTwo_bot](https://github.com/kreimben/ZeroTwo_bot) {os.getenv("ZEROTWO_VERSION")}!')
content = '1. Rewritten in Python.\n'
content += '2. Use multi-threading.\n'
content += '3. Remove weather and pollution features.\n'
content += '4. Remove sound filter features.\n'
content += '5. Fix ping command.\n'
content += '6. Add `force_quit` command to restart process.\n'
content += '7. Add repeat mode.\n'
content += '8. Support playlist.\n'
content += '9. Re-Implemented with new UI/UX.\n'
content += '10. Add `hey` command to get control panel.\n'
content += '11. Change `dance` gif image.\n'
content += '12. Add chapters info in queue.\n'
embed.add_field(name='Features', value=content)
embed.add_field(name='Thanks a lot!', value='[by kreimben](https://kreimben.com)')
return await context.respond(embed=embed)
@bot.slash_command(name='help')
async def _help(context: discord.ApplicationContext):
# For logging.
print('Command: help')
print(f'who: {context.author.name}')
embed = discord.Embed(title='Help', description='to help you')
content = 'aksidion@kreimben.com\n'
content += '[kreimben.com](https://kreimben.com)\n'
content += '[instagram](https://instagram.com/kreimben)\n'
content += '[paypal](https://paypal.me/kreimben)\n'
content += '[github](https://github.com/kreimben)\n'
embed.add_field(name='Contact to Kreimben#7005', value=content)
embed.add_field(name='Report to', value='[github](https://github.com/kreimben/ZeroTwo_bot/issues)')
return await context.respond(embed=embed)
try:
bot.run(os.getenv('DISCORD_TOKEN'))
except Exception as e:
print(str(e))