-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunCommands.cs
More file actions
340 lines (284 loc) · 10.7 KB
/
FunCommands.cs
File metadata and controls
340 lines (284 loc) · 10.7 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
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Attributes;
using DSharpPlus.Entities;
using DSharpPlus.Interactivity.Extensions;
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Wadebot;
public class FunCommands : BaseCommandModule
{
private static readonly Random rand = new Random();
#region Fun Commands
[Command("Speak")]
[Cooldown(1, 5, CooldownBucketType.User)]
public async Task Speak(CommandContext ctx)
{
string[] words =
{
"Hello", "Im not alive", "I was created in C#",
"Not all roads lead to rome", "absolute lamp",
"Hue Hue Hue", "Hello World", ":D",
"in the big 26 💔", "oh word?", "Cat"
};
string chosenWord = words[rand.Next(words.Length)];
if (chosenWord == "Cat")
{
string filepath = Path.Combine(
AppDomain.CurrentDomain.BaseDirectory,
"Cloe.png"
);
using var fs = new FileStream(filepath, FileMode.Open, FileAccess.Read);
await new DiscordMessageBuilder()
.WithContent("Cat")
.AddFile(fs)
.SendAsync(ctx.Channel);
}
else
{
await ctx.Channel.SendMessageAsync(chosenWord);
}
LogCommand(ctx, "Speak", chosenWord);
await HandleXpAsync(ctx);
}
/*
* Command : 8Ball
* Function : Wadebot will respond to a user's question with a random answer from the string array responses
* Cooldown : 1 use every 5 seconds per user
*/
[Command("8Ball")]
[Cooldown(1, 5, CooldownBucketType.User)]
public async Task EightBallCommand(CommandContext ctx, [RemainingText] string question)
{
string[] responses = { "Yes", "No", "Maybe", "Dont count on it", "Definitely", "Absolutely not", "Ask again later", "Allegedly", "I have no idea", "Perchance" };
string[] Faces = { ":)", ":(", ":/" };
string face = "";
Random rand = new Random();
string chosenResponse = responses[rand.Next(responses.Length)];
if (chosenResponse == responses[0] || chosenResponse == responses[4])
{
face = Faces[0];
}
else if (chosenResponse == responses[1] || chosenResponse == responses[3] || chosenResponse == responses[5])
{
face = Faces[1];
}
else
{
face = Faces[2];
}
await ctx.Channel.SendMessageAsync($"Question: {question}\nAnswer: {chosenResponse}\n{face}");
string timestamp = DateTime.Now.ToString("HH:mm:ss");
var user = ctx.User;
LogCommand(ctx, "8ball", $"{user} asked {question} WadeBot responded with :{chosenResponse}");
await HandleXpAsync(ctx);
}
[Command("RPS")]
[Cooldown(1, 5, CooldownBucketType.User)]
public async Task Rps(CommandContext ctx, string userChoice)
{
userChoice = userChoice.ToLower();
string[] choices = { "rock", "paper", "scissors" };
if (!choices.Contains(userChoice))
{
await ctx.RespondAsync("Choose **rock**, **paper**, or **scissors**.");
return;
}
string botChoice = choices[rand.Next(choices.Length)];
string result;
if (userChoice == botChoice)
result = "It's a tie! :O";
else if (
(userChoice == "rock" && botChoice == "scissors") ||
(userChoice == "paper" && botChoice == "rock") ||
(userChoice == "scissors" && botChoice == "paper")
)
result = "You win! :D";
else
result = "I win! :D";
await ctx.Channel.SendMessageAsync(
$"You chose **{userChoice}**. I chose **{botChoice}**. {result}"
);
LogCommand(ctx, "RPS", $"{ctx.User} vs bot — {result}");
await HandleXpAsync(ctx);
}
/*
* Command : Whisper
* Function : Wadebot will DM the user asking for a secret and randomly decide to keep it or snitch
* Cooldown : 1 use every 5 seconds per user
* ChatGPT helped me with this one :)
*/
[Command("Whisper")]
[Cooldown(1, 5, CooldownBucketType.User)]
public async Task Whisper(CommandContext ctx)
{
var user = ctx.Member;
var timestamp = DateTime.Now.ToString("HH:mm:ss");
if (user.IsBot)
{
await ctx.Channel.SendMessageAsync("❌ Bots cannot use this command.");
return;
}
// Step 1: Acknowledge in server
await ctx.Channel.SendMessageAsync("📩 Check your DMs…");
// Step 2: Create DM
DiscordDmChannel dm;
try
{
dm = await user.CreateDmChannelAsync();
}
catch
{
await ctx.Channel.SendMessageAsync("❌ I can't DM you. Please enable DMs.");
return;
}
// Step 3: Start DM conversation
await dm.SendMessageAsync("🤫 What is your secret?");
// Step 4: Wait for DM reply
var interactivity = ctx.Client.GetInteractivity();
var reply = await interactivity.WaitForMessageAsync(
m => m.Author.Id == user.Id && m.Channel.Id == dm.Id,
TimeSpan.FromSeconds(30)
);
if (reply.TimedOut)
{
await dm.SendMessageAsync("⌛ You took too long to reply.");
return;
}
string secret = reply.Result.Content;
// Step 5: Random response
bool snitch = rand.Next(0, 2) == 1;
string response;
if (!snitch)
{
response = "🤐 Your secret is safe with me.";
await ctx.Channel.SendMessageAsync("I aint no snitch");
LogCommand(ctx, "Whisper", $"{user} whispered: {secret} (Kept)");
}
else
{
response = $"📣 Yeah nah I'm snitching — {secret}";
await ctx.Channel.SendMessageAsync($"Wow I cant believe {user.Username} said '{secret}'");
LogCommand(ctx, "Whisper", $"{user} whispered: {secret} (snitched)");
}
// Step 6: Send DM response
await dm.SendMessageAsync(response);
await HandleXpAsync(ctx);
}
[Command("PokemonGuesser")]
[Cooldown(1, 5, CooldownBucketType.User)]
public async Task PokemonGuesser(CommandContext ctx)
{
var answerFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Pokemon.txt");
if (!File.Exists(answerFilePath))
{
await ctx.RespondAsync($"Technical Error: answers file not found at `{answerFilePath}`");
return;
}
var answers = File.ReadAllLines(answerFilePath)
.Select(s => s?.Trim())
.Where(s => !string.IsNullOrEmpty(s))
.ToArray();
if (answers.Length == 0)
{
await ctx.RespondAsync("Technical Error: answers file is empty.");
return;
}
// reuse a static Random or a shared instance in the class to avoid seed issues
int dexNumber = rand.Next(1, answers.Length + 1);
string filepath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Pokemon", $"{dexNumber}.png");
if (!File.Exists(filepath))
{
await ctx.RespondAsync($"Technical Error: I looked for the image at `{filepath}` but it wasn't there!");
return;
}
using (var fs = new FileStream(filepath, FileMode.Open, FileAccess.Read))
{
await new DiscordMessageBuilder()
.WithContent("Who's that Pokémon?")
.AddFile(fs)
.SendAsync(ctx.Channel);
}
string correctName = answers[dexNumber - 1];
var interactivity = ctx.Client.GetInteractivity();
var response = await interactivity.WaitForMessageAsync(
x => x.Content.Equals(correctName, StringComparison.OrdinalIgnoreCase) && x.Author.Id == ctx.User.Id,
TimeSpan.FromSeconds(45));
if (response.TimedOut)
await ctx.RespondAsync($"Time's up😒! It was {correctName}.");
else
await ctx.RespondAsync("🎉You are correct YIPPEE🎉");
LogCommand(ctx, "Pokemonguesser", $"{correctName} Was the chosen Pokemon");
await HandleXpAsync(ctx);
}
/*
* Command : Roulette
* Function : Wadebot will randomly select a non-bot member from the server and mention them in the channel
* Cooldown : 1 use every 5 seconds per user
*/
[Command("Roulette")]
[Cooldown(1, 5, CooldownBucketType.User)]
public async Task RouletteCommand(CommandContext ctx)
{
var members = await ctx.Guild.GetAllMembersAsync();
// Filter out bots so you only pick human members
var humans = members.Where(m => !m.IsBot).ToList();
if (humans.Count == 0)
{
await ctx.Channel.SendMessageAsync("No non-bot members found!");
return;
}
// Pick a random member
var chosen = humans[rand.Next(humans.Count)];
// Mention (ping) them
await ctx.Channel.SendMessageAsync($"Hey {chosen.Mention}, you’ve been chosen!");
string timestamp = DateTime.Now.ToString("HH:mm:ss");
var user = ctx.User;
LogCommand(ctx, "Roulette", $"{user} Pinged {chosen} with the bot");
await HandleXpAsync(ctx);
}
#endregion
//XP Handling Method
private async Task HandleXpAsync(CommandContext ctx, int xp = 10)
{
bool leveledUp = Database.AddXp(
ctx.User.Id,
ctx.Guild.Id,
xp,
out int newLevel
);
if (leveledUp)
{
await ctx.Channel.SendMessageAsync(
$"🎉 {ctx.User.Mention} reached **Level {newLevel}**!"
);
}
}
//Logging Method
private void LogCommand(
CommandContext ctx,
string command,
string output
)
{
using var connection = Database.GetConnection();
connection.Open();
var cmd = connection.CreateCommand();
cmd.CommandText =
@"
INSERT INTO Logs
(UserId, UserName, GuildId, GuildName, Command, Date, Output)
VALUES
($uid, $user, $gid, $gname, $cmd, $date, $out);
";
cmd.Parameters.AddWithValue("$uid", ctx.User.Id.ToString());
cmd.Parameters.AddWithValue("$user", ctx.User.Username);
cmd.Parameters.AddWithValue("$gid", ctx.Guild.Id.ToString());
cmd.Parameters.AddWithValue("$gname", ctx.Guild.Name);
cmd.Parameters.AddWithValue("$cmd", command);
cmd.Parameters.AddWithValue("$date", DateTime.Now.ToString("HH:mm:ss"));
cmd.Parameters.AddWithValue("$out", output);
cmd.ExecuteNonQuery();
}
}