Uh oh!
There was an error while loading. Please reload this page.
forked from EdsonHTJ/pythonDiscordBot
- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbot.py
More file actions
Latest commit
187 lines (140 loc) · 5.27 KB
/
Copy pathbot.py
File metadata and controls
187 lines (140 loc) · 5.27 KB
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
importdiscord
fromdiscordimportmessage
fromdiscord.extimportcommands
fromdiscord.ext.commands.coreimportcommand
frommusic.musicimportgetVideoInfo
frompycoingeckoimportCoinGeckoAPI
frombattleRoyale.battleimportBattleRoyale
importasyncio
fromthreadingimportThread
importtime
fromrandomimportrandint
classbot(commands.Cog):
def__init__(self, client):
self.client=client
self.urlQueue= []
self.br=BattleRoyale()
self.hidePlay=False
@commands.command()
asyncdefjoin(self, ctx):
ifctx.author.voiceisNone:
awaitctx.send("no one in voice channel")
voice_channel=ctx.author.voice.channel
ifctx.voice_clientisNone:
awaitvoice_channel.connect()
else:
awaitctx.voice_client.move_to(voice_channel)
@commands.command()
asyncdefdisconnect(self, ctx):
awaitctx.voice_client.disconnect()
@commands.command()
asyncdefqueue(self, ctx, *inputs):
url=''.join(inputs)
awaitself.addItemToQueue(ctx, url)
@commands.command()
asyncdefplay(self, ctx, *inputs):
url=''.join(inputs)
awaitself.join(ctx)
ifurl=='':
self.playNextVideo(ctx)
return
awaitself.addItemToQueue(ctx, url)
ifctx.voice_client.is_playing() ==0:
self.playNextVideo(ctx=ctx)
asyncdefaddItemToQueue(self, ctx, url):
info, source=awaitgetVideoInfo(url)
self.urlQueue.append( (info, source) )
ifnotself.hidePlay:
awaitctx.send(f"Added -> {info.get('title', None)}")
defplayNextVideo(self, ctx):
iflen(self.urlQueue) ==0:
ctx.voice_client.stop()
return
info, source=self.urlQueue[0]
self.urlQueue=self.urlQueue[1:]
self.playVideo(ctx, info, source)
defplayVideo(self, ctx, info , source):
vc=ctx.voice_client
vc.stop()
video_title=info.get('title', None)
video_id=info.get("id", None)
ifnotself.hidePlay:
self.send(ctx, f"playing: {video_title}\nhttps://www.youtube.com/watch?v={video_id}")
print(f"playing: {video_title}\nhttps://www.youtube.com/watch?v={video_id}")
#await ctx.send(f"playing: {video_title} \nhttps://www.youtube.com/watch?v={video_id}")
vc.play(source, after=lambda_: self.playNextVideo(ctx) )
defsend(self, ctx, message):
try:
loop=asyncio.get_event_loop()
loop.create_task(ctx.send(message))
except:
pass
@commands.command()
asyncdefskip(self, ctx):
ctx.send("Skipping Video")
self.playNextVideo(ctx)
@commands.command()
asyncdefpause(self, ctx):
awaitctx.voice_client.pause()
awaitctx.send("Paused")
@commands.command()
asyncdefresume(self, ctx):
awaitctx.voice_client.resume()
awaitctx.send("resumed")
@commands.command()
asyncdefalyson(self, ctx):
awaitctx.send("CLUBISTA MASTER")
@commands.command()
asyncdefcorno(self, ctx):
channel=self.client.get_channel(ctx.author.voice.channel.id)
vm=channel.members
awaitctx.send(f"Existem {len(vm)} possiveis cornos")
formemberinvm:
awaitctx.send(member.mention)
ri=randint(0, len(vm) -1)
awaitctx.send(f"mas {vm[ri].mention} sem duvida é o maior deles")
@commands.command()
asyncdefcoin(self, ctx, *kwargs):
coin=kwargs[0]
if(len(kwargs) <2):
vsc='usd'
else:
vsc=kwargs[1]
cg=CoinGeckoAPI()
price=cg.get_price(ids=coin, vs_currencies=vsc)
awaitctx.send(f"{coin.title()}: {price[coin][vsc]}{vsc.upper()}")
@commands.command()
asyncdefbr(self, ctx, *args):
arg=args[0]
ifarg=="new":
awaitctx.send("New beto Real Game")
self.br=BattleRoyale()
elifarg=="add":
iflen(args) <2:
awaitctx.send("inform player")
return
names=args[1:]
fornameinnames:
self.br.addPlayer(name)
elifarg=="run":
lines=self.br.run()
forlineinlines:
time.sleep(3)
if("colour"inline):
embed=discord.Embed(colour=line["colour"], description=line["message"])
else:
embed=discord.Embed(description=line)
if("img_url"inline):
embed.set_image(url=line["img_url"])
if("footer"inline):
embed.set_footer(text=line["footer"]["text"], icon_url=line["footer"]["icon_url"])
if("music"inline):
self.hidePlay=True
awaitself.join(ctx)
ifctx.voice_client.is_playing():
ctx.voice_client.stop()
awaitself.play(ctx, line["music"])
self.hidePlay=False
awaitctx.send(embed=embed)
defsetup(client):
client.add_cog(bot(client))