-
Notifications
You must be signed in to change notification settings - Fork 0
/
Entertainment.cs
496 lines (443 loc) · 17.9 KB
/
Entertainment.cs
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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Discord;
using Discord.WebSocket;
using Discord.Commands;
using Google.Apis.YouTube.v3;
using RawBotFYP_GUI_.Core.Data;
using Newtonsoft.Json.Linq;
using RawBotFYP.Core.Services;
using Google.Apis.Services;
using System.Diagnostics;
using Discord.Audio;
using RawBotFYP_GUI_.Core.Services;
using Microsoft.Extensions.DependencyInjection;
using System.Net.Http;
using Discord.Rest;
using System.Collections.Concurrent;
//entertainment commands for fun.
namespace RawBotFYP_GUI_.Core.Commands
{
#region Methods
public class EntertainMethods
{
public EmbedBuilder CreateEmbled(string Author, string Description) // Methods to Create a Embled
{
EmbedBuilder Embedb = new EmbedBuilder();
Embedb.WithAuthor(Author);
Embedb.WithColor(40, 200, 150);
Embedb.WithDescription(Description);
Embedb.Build();
return Embedb;
}
}
#endregion
#region Jokes
public class Jokes : ModuleBase<SocketCommandContext>
{
StoreJokes CallJoke = new StoreJokes();
[Command("jokes")]
public async Task sayJoke() // Execute jokes
{
Random randjoke = new Random();
int randomgen = randjoke.Next(1, CallJoke.JokeRNG.Count);
string CallrandJoke = CallJoke.JokeRNG[randomgen];
await ReplyAsync($"**Jokes Number :** {randomgen} \n{CallrandJoke}", true);
}
}
#endregion
#region Ping
public class Ping : ModuleBase<SocketCommandContext>
{
[Command("Ping")] // Ping , Pong.
public async Task PingPong()
{
await Context.Channel.SendMessageAsync($"Pong :ping_pong: {Context.Client.Latency}");
}
}
#endregion
#region RollDice
public class RollDice : ModuleBase<SocketCommandContext>
{
ModerationMethods getMethods = new ModerationMethods();
[Command("Roll")] // Roll Dice with number
public async Task sayRollNum([Remainder] int rNum)
{
Random RNG = new Random();
int random = RNG.Next(1, (rNum + 1));
await ReplyAsync($":game_die: Number Rolled: {random}");
}
[Command("roll")] // If Dice command has string parameter
public async Task ifRollstring([Remainder] string rNum)
{
await Context.Channel.SendMessageAsync("", false, getMethods.CreateEmbled("Invalid Command", $"{rNum} is not a Integer.\nPlease have an Integer after the !roll command. Example: !roll 30."));
}
[Command("roll")] // if Dice command has no paramater
public async Task ifnorollnum()
{
await Context.Channel.SendMessageAsync("", false, getMethods.CreateEmbled("Invalid Command", "Please have an Integer after the !roll command. Example: !roll 30."));
}
}
#endregion
#region Pickuser/LuckyDraw
public class PickUser : ModuleBase<SocketCommandContext>
{
[RequireBotPermission(GuildPermission.Administrator)]
[RequireUserPermission(GuildPermission.Administrator)]
[Command("PickUser")]
public async Task userpick()
{
Random RNGUser = new Random();
List<string> UserArrayFiltered = new List<string>();
foreach (SocketGuildUser User in Context.Guild.Users)
{
if (!User.IsBot)
{
if (User.Status.Equals(UserStatus.Online) && !User.Equals(Context.Message.Author))
{
UserArrayFiltered.Add(User.Username);
}
}
}
int numofusers = RNGUser.Next(0, UserArrayFiltered.Count);
await Context.Channel.SendMessageAsync("Congrats to " + UserArrayFiltered[numofusers] + " for winning the Giveaway!!");
}
[Command("PickUser")]
public async Task UserRequire()
{
await ReplyAsync("You do not have the required permissions to run the bot!");
}
}
#endregion
#region Define
public class defining : ModuleBase<SocketCommandContext>
{
[Command("define")]
public async Task Dictionary([Remainder] string word = null)
{
if (string.IsNullOrWhiteSpace(word))
{
//if word is empty/missing
var embed = new EmbedBuilder();
embed.Title = "Defining " + word;
embed.WithColor(52, 152, 219);
embed.Description = ":warning: A word or phrase is required!";
await Context.Channel.SendMessageAsync("", false, embed.Build());
}
else
{
var data = await Commonservice.DefinitionService.GetDefinitionForTermAsync(word);
if (data.Results.Count == 0)
{
//if word can't be found
var embed = new EmbedBuilder();
embed.Title = "can't find the explantion for " + word;
embed.WithColor(52, 152, 219);
embed.Description = "No results found!";
await Context.Channel.SendMessageAsync("", false, embed.Build());
}
else
for (var index = 0; index < data.Results.Count; index++)
foreach (var value in data.Results[index].Senses)
if (value.Definition != null)
{
var definition = value.Definition.ToString();
if (!(value.Definition is string))
definition = ((JArray)JToken.Parse(value.Definition.ToString())).First.ToString();
var output = new EmbedBuilder()
.WithTitle($"Dictionary definition for **{word}**")
.WithDescription(definition.Length < 500 ? definition : definition.Take(500) + "...")
.WithColor(52, 152, 219);
if (value.Examples != null)
output.AddField("Example", value.Examples.First().text);
await Context.Channel.SendMessageAsync("", false, output.Build());
index = data.Results.Count;
break;
}
}
}
}
#endregion
#region youtubeSearch
public class youtubeSearch : ModuleBase<SocketCommandContext>
{
[Command("Youtube")]
public async Task Youtube([Remainder] string Ysearching)
{
var youtubeService = new YouTubeService(new BaseClientService.Initializer()
{
ApiKey = "AIzaSyCiDVoN9suAf6QR97UC6Ca_88RBwVi_yAI",
ApplicationName = GetType().ToString()
});
var searchListRequest = youtubeService.Search.List("snippet");
searchListRequest.Q = Ysearching;
searchListRequest.MaxResults = 1;
// Call the search.list method to retrieve results matching the specified query term.
var searchListResponse = await searchListRequest.ExecuteAsync();
List<string> videos = new List<string>();
List<string> channels = new List<string>();
// Add each result to the appropriate list, and then display the lists of
// matching videos and channels.
foreach (var searchResult in searchListResponse.Items)
{
switch (searchResult.Id.Kind)
{
case "youtube#video":
videos.Add(String.Format("{0} ({1})", searchResult.Snippet.Title, searchResult.Id.VideoId));
await Context.Channel.SendMessageAsync("https://youtube.com/watch?v=" + searchResult.Id.VideoId);
break;
case "youtube#channel":
channels.Add(String.Format("{0} ({1})", searchResult.Snippet.Title, searchResult.Id.ChannelId));
await Context.Channel.SendMessageAsync("https://www.youtube.com/channel/" + searchResult.Id.ChannelId);
break;
}
}
Console.WriteLine(String.Format("Videos:\n{0}\n", string.Join("\n", videos)));
Console.WriteLine(String.Format("Channels:\n{0}\n", string.Join("\n", channels)));
}
}
#endregion
#region poll
public class poll : ModuleBase<SocketCommandContext>
{
[Command("Poll")]
public async Task Polling([Remainder]string text = null)
{
var embed = new EmbedBuilder();
embed.WithColor(10, 10, 10);
embed.WithTitle("Poll Created By " + Context.User);
embed.WithDescription($"*{text}*");
embed.WithFooter("React to vote.");
RestUserMessage notice = await Context.Channel.SendMessageAsync("", false, embed.Build());
await notice.AddReactionAsync(new Emoji("✅"));
await notice.AddReactionAsync(new Emoji("❌"));
}
}
#endregion
#region calculator
public class cal : ModuleBase<SocketCommandContext>
{
[Command("Math")]
public async Task Math(double num1, string symbol, double num2)
{
double result;
switch (symbol)
{
case "+":
result = num1 + num2;
break;
case "-":
result = num1 - num2;
break;
case "*":
result = num1 * num2;
break;
case "/":
result = num1 / num2;
break;
case "%":
result = num1 % num2;
break;
default:
result = num1 + num2;
break;
}
var answer = new EmbedBuilder();
answer.WithTitle($":white_check_mark: The result is {result:#,##0.00}");
answer.WithColor(40, 200, 150);
await Context.Channel.SendMessageAsync("", false, answer.Build());
}
[Command("Math")]
public async Task invalid(string word = null, string symbol = null, string word2 = null)
{
await Context.Channel.SendMessageAsync("Invalid! Please follow this format : number + number :slight_smile:");
}
}
#endregion
#region catfact
public class catfacts : ModuleBase<SocketCommandContext>
{
[Command("Catfact")]
public async Task Catfact()
{
using (var http = new HttpClient())
{
var response = await http.GetStringAsync($"https://catfact.ninja/fact").ConfigureAwait(false);
if (response == null)
return;
var fact = JObject.Parse(response)["fact"].ToString();
await Context.Channel.SendMessageAsync("🐈" + ("catfact! ") + fact).ConfigureAwait(false);
}
}
}
#endregion
#region dogfact
public class dogfacts : ModuleBase<SocketCommandContext>
{
[Command("Dogfact")]
public async Task dogfact()
{
using (var http = new HttpClient())
{
var response = await http.GetStringAsync($"http://dog-api.kinduff.com/api/facts").ConfigureAwait(false);
if (response == null)
return;
var fact = JObject.Parse(response)["facts"].ToString();
await Context.Channel.SendMessageAsync("🐕 Dogfact!" + fact).ConfigureAwait(false);
}
}
}
#endregion
#region catPic
public class Catpic : ModuleBase<SocketCommandContext>
{
[Command("Catpic")]
public async Task CatPic()
{
using (HttpClient client = new HttpClient())
{
var Picresponse = new EmbedBuilder();
string url = null;
string data = await client.GetStringAsync("https://aws.random.cat/meow");
var dData = JObject.Parse(data);
url = dData["file"].ToString();
Picresponse.WithImageUrl(url);
await Context.Channel.SendMessageAsync("", false, Picresponse.Build());
}
}
}
#endregion
#region dogPic
public class Docpic : ModuleBase<SocketCommandContext>
{
[Command("Dogpic")]
public async Task CatPic()
{
using (HttpClient client = new HttpClient())
{
var Picresponse = new EmbedBuilder();
string url = null;
string data = await client.GetStringAsync("https://random.dog/woof.json");
var dData = JObject.Parse(data);
url = dData["url"].ToString();
Picresponse.WithImageUrl(url);
await Context.Channel.SendMessageAsync("", false, Picresponse.Build());
}
}
}
#endregion
#region BirdPic
public class Birdpic : ModuleBase<SocketCommandContext>
{
[Command("Birdpic")]
public async Task BirdPic()
{
using (HttpClient client = new HttpClient())
{
var Picresponse = new EmbedBuilder();
string url = null;
string data = await client.GetStringAsync("https://birdsare.cool/bird.json");
var dData = JObject.Parse(data);
url = dData["url"].ToString();
Picresponse.WithImageUrl(url);
await Context.Channel.SendMessageAsync("", false, Picresponse.Build());
}
}
}
#endregion
#region music
//public class joining : ModuleBase<SocketCommandContext>
//{
// private readonly ConcurrentDictionary<ulong, IAudioClient> ConnectedChannels = new ConcurrentDictionary<ulong, IAudioClient>();
// //public AudioService _service;
// //Remember to add an instance of the AudioService
// // to your IServiceCollection when you initialize your bot
// //public joining(AudioService service)
// //{
// // _service = service;
// //}
// [Command("Create", RunMode = RunMode.Async)]
//public async Task CreateVoiceChannel([Remainder]string name = "General")
//{
// await Context.Guild.CreateVoiceChannelAsync(name);
//}
//[Command("Join", RunMode = RunMode.Async)]
//public async Task JoinChannel(IVoiceChannel channel = null)
//{
// // Get the audio channel
// channel = channel ?? (Context.Message.Author as IGuildUser)?.VoiceChannel;
// if (channel == null)
// {
// await Context.Channel.SendMessageAsync("User must be in a voice channel.");
// return;
// }
// // For the next step with transmitting audio, you would want to pass this Audio Client in to a service.
// var audioClient = await channel.ConnectAsync();
//}
// // [Command("play", RunMode = RunMode.Async)]
// //public async Task PlayCmd([Remainder] string song)
// //{
// // await (Context.Guild, Context.Channel, song);
// //}
// private Process CreateStream(string path)
//{
// try
// {
// return Process.Start(new ProcessStartInfo
// {
// FileName = "ffmpeg",
// Arguments = $"-hide_banner -loglevel panic -i \"{path}\" -ac 2 -f s16le -ar 48000 pipe:1",
// UseShellExecute = false,
// RedirectStandardOutput = true,
// CreateNoWindow = true
// });
// }
// catch
// {
// Console.WriteLine($"Error while opening local stream : {path}");
// return null;
// }
//}
//private async Task SendAsync(IAudioClient client, string path)
//{
// // Create FFmpeg using the previous example
// using (var ffmpeg = CreateStream(path))
// using (var output = ffmpeg.StandardOutput.BaseStream)
// using (var discord = client.CreatePCMStream(AudioApplication.Mixed))
// {
// try { await output.CopyToAsync(discord); }
// finally { await discord.FlushAsync(); }
// }
//}
}
public class AudioModule : ModuleBase<ICommandContext>
{
// Scroll down further for the AudioService.
// Like, way down
private readonly AudioService _service;
// Remember to add an instance of the AudioService
// to your IServiceCollection when you initialize your bot
public AudioModule(AudioService service)
{
_service = service;
}
// You *MUST* mark these commands with 'RunMode.Async'
// otherwise the bot will not respond until the Task times out.
[Command("join", RunMode = RunMode.Async)]
public async Task JoinCmd()
{
await _service.JoinAudio(Context.Guild, (Context.User as IVoiceChannel));
}
//Remember to add preconditions to your commands,
// this is merely the minimal amount necessary.
// Adding more commands of your own is also encouraged.
[Command("play", RunMode = RunMode.Async)]
public async Task PlayCmd([Remainder] string song)
{
await _service.SendAudioAsync(Context.Guild, Context.Channel, song);
}
#endregion
}