-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
129 lines (115 loc) · 4.46 KB
/
Copy pathProgram.cs
File metadata and controls
129 lines (115 loc) · 4.46 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
using Discord;
using Discord.Commands;
using Discord.WebSocket;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Reflection;
using System.Threading.Tasks;
using Discord.Net.Providers.WS4Net;
using System.Collections.Generic;
using System.IO;
namespace DabSquadBot
{
class Program
{
private readonly DiscordSocketClient client;
// Keep the CommandService and IServiceCollection around for use with commands.
private IServiceCollection _map = new ServiceCollection();
private CommandService _commands = new CommandService();
// Program entry point
static void Main(string[] args)
{
// Call the Program constructor, followed by the
// MainAsync method and wait until it finishes (which should be never).
new Program().MainAsync().GetAwaiter().GetResult();
}
private Program()
{
client = new DiscordSocketClient(new DiscordSocketConfig
{
LogLevel = LogSeverity.Info,
#if (!DEBUG)
WebSocketProvider = WS4NetProvider.Instance
#endif
});
}
// Example of a logging handler. This can be re-used by addons
// that ask for a Func<LogMessage, Task>.
private static Task Logger(LogMessage message)
{
var cc = Console.ForegroundColor;
switch (message.Severity)
{
case LogSeverity.Critical:
case LogSeverity.Error:
Console.ForegroundColor = ConsoleColor.Red;
break;
case LogSeverity.Warning:
Console.ForegroundColor = ConsoleColor.Yellow;
break;
case LogSeverity.Info:
Console.ForegroundColor = ConsoleColor.White;
break;
case LogSeverity.Verbose:
case LogSeverity.Debug:
Console.ForegroundColor = ConsoleColor.DarkGray;
break;
}
Console.WriteLine($"{DateTime.Now,-19} [{message.Severity,8}] {message.Source}: {message.Message}");
Console.ForegroundColor = cc;
// If you get an error saying 'CompletedTask' doesn't exist,
// your project is targeting .NET 4.5.2 or lower. You'll need
// to adjust your project's target framework to 4.6 or higher
// (instructions for this are easily Googled).
// If you *need* to run on .NET 4.5 for compat/other reasons,
// the alternative is to 'return Task.Delay(0);' instead.
return Task.CompletedTask;
}
private async Task MainAsync()
{
try
{
client.Log += Logger;
client.Ready += Ready;
client.MessageReceived += MessageReceived;
//Bot token goes here. Your list of bots can be found here: https://discordapp.com/developers/applications/
string token = ""; // Remember to keep this private!
await client.LoginAsync(TokenType.Bot, token);
await client.StartAsync();
// Block this task until the program is closed.
await Task.Delay(-1);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
private Task Ready()
{
Global.InitGlobalVars();
return Task.CompletedTask;
}
string previousImage = "";
string currentImage = "";
private async Task MessageReceived(SocketMessage msg)
{
try
{
if (msg.Content.ToLower().Contains("dab"))
{
Random rnd = new Random();
Global.Data = Global.JSONHelper.JsonDeserialize();
Global.Data.DabImages.Remove(previousImage);
currentImage = Global.Data.DabImages[rnd.Next(Global.Data.DabImages.Count - 1)];
await msg.Channel.SendMessageAsync("", embed: new EmbedBuilder() { ImageUrl = currentImage, Color = Global.Colors[rnd.Next(Global.Colors.Count - 1)] }.Build());
Global.Data.DabImages.Add(previousImage);
previousImage = currentImage;
}
}
catch(Exception ex)
{
Global.LogError(ex);
}
}
}
}