-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
125 lines (101 loc) · 3.97 KB
/
Program.cs
File metadata and controls
125 lines (101 loc) · 3.97 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
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using DSharpPlus;
using DSharpPlus.CommandsNext;
using DSharpPlus.Entities;
using DSharpPlus.Interactivity;
using DSharpPlus.Interactivity.Extensions;
using DSharpPlus.VoiceNext;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
namespace AmongUsDriver
{
class Program
{
public static DiscordClient discord;
static CommandsNextExtension commands;
static InteractivityExtension interactivity;
static VoiceNextExtension voiceNext;
static void Main(string[] args)
{
//Console.WriteLine("Hello World!");
// Bot Start
MainAsync().GetAwaiter().GetResult();
}
static async Task MainAsync()
{
// Reads token and prefix from config.json located in project dir.
var json = string.Empty;
using (var fs = File.OpenRead("config.json"))
using (var sr = new StreamReader(fs, new UTF8Encoding(false)))
json = await sr.ReadToEndAsync();
var configJson = JsonConvert.DeserializeObject<ConfigJson>(json);
// Discord Config
var discordConfig = new DiscordConfiguration
{
Token = configJson.Token,
TokenType = TokenType.Bot,
MinimumLogLevel = LogLevel.Debug,
LogTimestampFormat = "MMM dd yyyy - hh:mm:ss tt"
};
discord = new DiscordClient(discordConfig);
// Interactivity Config
var interactivityConfig = new InteractivityConfiguration
{
Timeout = TimeSpan.FromMinutes(5)
};
interactivity = discord.UseInteractivity(interactivityConfig);
// Voice Next Config
var voiceNextConfig = new VoiceNextConfiguration
{
EnableIncoming = false
};
voiceNext = discord.UseVoiceNext(voiceNextConfig);
// Commands Config
var commandsConfig = new CommandsNextConfiguration
{
StringPrefixes = new string[] { configJson.Prefix },
IgnoreExtraArguments = false,
};
commands = discord.UseCommandsNext(commandsConfig);
// Linking myCommands
commands.RegisterCommands<myCommands>();
// In Event of a command error do this:
commands.CommandErrored += Commands_CommandErrored;
// When bot is ready...
discord.Ready += Discord_Ready;
//
// BOT 'PLAYING...'
DiscordActivity discordActivity = new DiscordActivity();
discordActivity.ActivityType = ActivityType.Playing;
discordActivity.Name = "Among Us | .help";
// Connect and wait indefinitely.
await discord.ConnectAsync(discordActivity);
await Task.Delay(-1);
}
private static Task Discord_Ready(DiscordClient sender, DSharpPlus.EventArgs.ReadyEventArgs e)
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Ready!");
Console.ResetColor();
return Task.CompletedTask;
}
private static async Task Commands_CommandErrored(CommandsNextExtension sender, CommandErrorEventArgs e)
{
if (e.Context.Message.Content[0].ToString() == "." && e.Context.Message.Content[1].ToString() == "." ||
e.Context.Message.Content[0].ToString() == "." && e.Context.Message.Content[1].ToString() == "_")
{
// ignore
await Task.CompletedTask;
}
else
{
await e.Context.RespondAsync($"{e.Context.Member.Mention}, Command Error! - Stuck? Use '.help'");
}
}
}
}