3
3
information commands for BB.Bot.
4
4
"""
5
5
import datetime
6
+ import random
6
7
import discord
7
8
import humanize
8
9
import twitchio
12
13
from discord import app_commands
13
14
from discord .ext import commands
14
15
16
+ from ext .views .youtube_view import YoutubeView
17
+
15
18
16
19
class Misc (commands .Cog , name = "Miscellaneous" ):
17
20
"""
@@ -31,7 +34,7 @@ async def twitch(self, interaction: discord.Interaction, *, broadcaster: str) ->
31
34
32
35
if not streams :
33
36
error_embed = utils .create_error_embed (f"The streamer **`{ broadcaster } `** is not currently live." )
34
- return await interaction .response .send_message (embed = error_embed )
37
+ return await interaction .response .send_message (embed = error_embed , ephemeral = True )
35
38
36
39
stream : twitchio .Stream = streams [0 ]
37
40
current_time = datetime .datetime .utcnow ()
@@ -55,6 +58,30 @@ async def twitch(self, interaction: discord.Interaction, *, broadcaster: str) ->
55
58
.add_field (name = "❓ Category" , value = stream .game_name , inline = False )
56
59
57
60
await interaction .response .send_message (embed = stream_embed )
61
+
62
+ @app_commands .command ()
63
+ @app_commands .describe (choices = "❓ The choices to choose from, separated by commas." )
64
+ async def choose (self , interaction : discord .Interaction , * , choices : str ):
65
+ """
66
+ 🎲 Chooses a random option from a list of choices.
67
+ """
68
+ choices = [x .strip () for x in choices .split ("," )]
69
+
70
+ if len (choices ) <= 1 :
71
+ error_embed = utils .create_error_embed ("You need to give me at least 2 choices." )
72
+ return await interaction .response .send_message (embed = error_embed , ephemeral = True )
73
+
74
+ numbered_choices = [f"**`{ i + 1 } `** — { x } " for i , x in enumerate (choices )]
75
+
76
+ choice_embed = discord .Embed (
77
+ title = "🎲 My Choice" ,
78
+ description = f"**`{ random .choice (choices )} `**" ,
79
+ timestamp = datetime .datetime .utcnow (),
80
+ color = self .client .theme ,
81
+ ) \
82
+ .add_field (name = "❗ Options Given" , value = "\n " .join (numbered_choices ))
83
+
84
+ await interaction .response .send_message (embed = choice_embed )
58
85
59
86
@app_commands .command ()
60
87
async def meme (self , interaction : discord .Interaction ):
@@ -63,14 +90,15 @@ async def meme(self, interaction: discord.Interaction):
63
90
"""
64
91
response = await self .client .session .get ("https://meme-api.herokuapp.com/gimme" )
65
92
data = await response .json ()
93
+ url = data ['url' ]
66
94
67
95
meme_embed = discord .Embed (
68
96
title = "🎲 Found a Meme" ,
69
- description = f"**` { data ['title' ]} ` **" ,
97
+ description = f"**[ { data ['title' ]} ]( { url } ) **" ,
70
98
timestamp = datetime .datetime .utcnow (),
71
- color = self .client .theme ,
99
+ color = self .client .theme ,
72
100
) \
73
- .set_image (url = f"{ data [ ' url' ] } " ) \
101
+ .set_image (url = f"{ url } " ) \
74
102
.set_footer (text = "❓ Try again? Use /meme." )
75
103
76
104
await interaction .response .send_message (embed = meme_embed )
@@ -81,19 +109,93 @@ async def poll(self, interaction: discord.Interaction, *, question: str):
81
109
"""
82
110
🎲 Creates a simple yes or no poll for users to vote on.
83
111
"""
112
+ if message is None :
113
+ error_embed = utils .create_error_embed ("You need to ask a question." )
114
+ return await interaction .response .send_message (embed = error_embed )
115
+
84
116
poll_embed = discord .Embed (
85
117
title = "🎲 Poll" ,
86
118
description = f"**`{ question } `**" ,
87
119
timestamp = datetime .datetime .utcnow (),
88
120
color = self .client .theme ,
89
121
) \
90
- .set_author (name = interaction .user .name , url = interaction .user .avatar .url ) \
122
+ .set_author (name = interaction .user .name , icon_url = interaction .user .avatar .url ) \
91
123
.set_footer (text = "Vote ✔️ Yes or ❌ No." )
92
124
93
125
message = await interaction .channel .send (embed = poll_embed )
94
126
await message .add_reaction ("✔️" )
95
127
await message .add_reaction ("❌" )
128
+
129
+ @app_commands .command ()
130
+ @app_commands .describe (message = "❓ The phrase you want the bot to repeat." )
131
+ async def echo (self , interaction : discord .Interaction , * , message : str ):
132
+ """
133
+ 🎲 Repeats what you say.
134
+ """
135
+ if message is None :
136
+ error_embed = utils .create_error_embed ("You need to tell me what to say." )
137
+ return await interaction .response .send_message (embed = error_embed )
138
+
139
+ echo_embed = discord .Embed (
140
+ title = f"🎲 Message" ,
141
+ description = f"**`{ message } `**" ,
142
+ timestamp = datetime .datetime .utcnow (),
143
+ color = self .client .theme ,
144
+ ) \
145
+ .set_author (name = interaction .user .name , icon_url = interaction .user .avatar .url )
146
+
147
+ await interaction .response .send_message (embed = echo_embed )
148
+
149
+ @app_commands .command ()
150
+ async def ping (self , interaction : discord .Interaction ):
151
+ """
152
+ 🎲 Shows the bot's current websocket latency.
153
+ """
154
+ await interaction .response .defer ()
155
+
156
+ embed = discord .Embed (
157
+ title = "🏓 Pong!" ,
158
+ description = f"⌛ Your ping is **{ round (self .client .latency * 1000 )} **ms." ,
159
+ timestamp = datetime .datetime .utcnow (),
160
+ color = self .client .theme ,
161
+ )
162
+
163
+ await interaction .followup .send (embed = embed )
164
+
165
+ @app_commands .command ()
166
+ @app_commands .describe (search = "❓ The YouTube video to search for." )
167
+ async def youtube (self , interaction : discord .Interaction , * , search : str ):
168
+ """
169
+ 🎲 Searches for a video on youtube and sends the link.
170
+ """
171
+ if search is None :
172
+ error_embed = utils .create_error_embed ("You need to specify a search term." )
173
+ return await interaction .response .send_message (embed = error_embed )
174
+
175
+ url = await utils .youtube_search_to_url (search )
176
+ title = await utils .youtube_url_to_title (url )
177
+ thumbnail = await utils .youtube_url_to_thumbnail (url )
178
+
179
+ embed = discord .Embed (
180
+ title = "🎲 Found a Video" ,
181
+ description = f"🔗 [{ title } ]({ url } )" ,
182
+ timestamp = datetime .datetime .utcnow (),
183
+ color = self .client .theme ,
184
+ ) \
185
+ .set_thumbnail (url = thumbnail ) \
186
+ .set_footer (text = f"❓ Follow the link above to view the video." )
187
+
188
+ await interaction .response .send_message (embed = embed )
189
+
190
+ embed = discord .Embed (
191
+ title = "🎲 View in Discord?" ,
192
+ description = "❓ Click View In Discord to view the video in this text channel." ,
193
+ timestamp = datetime .datetime .utcnow (),
194
+ color = self .client .theme ,
195
+ )
96
196
197
+ view = YoutubeView (url , interaction )
198
+ view .message = await interaction .followup .send (embed = embed , view = view )
97
199
98
200
99
201
async def setup (client : core .DiscordClient ) -> None :
0 commit comments