NadekoBot/NadekoBot/NadekoBot.cs

95 lines
3.3 KiB
C#
Raw Normal View History

2015-12-05 10:27:00 +00:00
using Discord;
using System;
using System.IO;
using Newtonsoft.Json;
using Parse;
using Discord.Commands;
2015-12-05 10:27:00 +00:00
using NadekoBot.Modules;
using Discord.Modules;
2015-12-30 04:44:36 +00:00
using Discord.Legacy;
2015-12-31 19:40:09 +00:00
using Discord.Audio;
2015-12-05 10:27:00 +00:00
namespace NadekoBot
{
class NadekoBot
{
public static DiscordClient client;
public static StatsCollector stats_collector;
2015-12-05 10:27:00 +00:00
public static string botMention;
public static string GoogleAPIKey = null;
public static ulong OwnerID;
2015-12-30 04:44:36 +00:00
public static string password;
2015-12-05 10:27:00 +00:00
static void Main()
2015-12-05 10:27:00 +00:00
{
//load credentials from credentials.json
Credentials c;
try
{
c = JsonConvert.DeserializeObject<Credentials>(File.ReadAllText("credentials.json"));
botMention = c.BotMention;
if (c.GoogleAPIKey == null || c.GoogleAPIKey == "") {
Console.WriteLine("No google api key found. You will not be able to use music and links won't be shortened.");
}
2015-12-05 10:27:00 +00:00
OwnerID = c.OwnerID;
2015-12-30 04:44:36 +00:00
password = c.Password;
2015-12-05 10:27:00 +00:00
}
catch (Exception)
{
Console.WriteLine("Failed to load stuff from credentials.json, RTFM");
Console.ReadKey();
return;
}
//create new discord client
client = new DiscordClient();
2015-12-05 10:27:00 +00:00
//create a command service
var commandService = new CommandService(new CommandServiceConfig
{
CommandChar = null,
HelpMode = HelpMode.Disable
});
//init parse
if (c.ParseKey != null && c.ParseID != null && c.ParseID != "" && c.ParseKey != "") {
ParseClient.Initialize(c.ParseID, c.ParseKey);
//monitor commands for logging
stats_collector = new StatsCollector(commandService);
} else {
Console.WriteLine("Parse key and/or ID not found. Bot will not log.");
}
2015-12-05 10:27:00 +00:00
//add command service
2015-12-30 04:44:36 +00:00
var commands = client.Services.Add<CommandService>(commandService);
2015-12-05 10:27:00 +00:00
//create module service
2015-12-30 04:44:36 +00:00
var modules = client.Services.Add<ModuleService>(new ModuleService());
2015-12-05 10:27:00 +00:00
2015-12-31 19:40:09 +00:00
//add audio service
var audio = client.Services.Add<AudioService>(new AudioService(new AudioServiceConfig() {
Channels = 2,
EnableEncryption = false
2015-12-31 19:40:09 +00:00
}));
2015-12-05 10:27:00 +00:00
//install modules
modules.Install(new Administration(), "Administration", FilterType.Unrestricted);
2015-12-06 13:22:30 +00:00
modules.Install(new Conversations(), "Conversations", FilterType.Unrestricted);
2015-12-05 10:27:00 +00:00
modules.Install(new Gambling(), "Gambling", FilterType.Unrestricted);
modules.Install(new Games(), "Games", FilterType.Unrestricted);
2015-12-31 19:40:09 +00:00
modules.Install(new Music(), "Music", FilterType.Unrestricted);
2015-12-05 10:27:00 +00:00
modules.Install(new Searches(), "Searches", FilterType.Unrestricted);
//run the bot
client.Run(async () =>
{
await client.Connect(c.Username, c.Password);
Console.WriteLine("Connected!");
2015-12-05 10:27:00 +00:00
});
Console.WriteLine("Exiting...");
Console.ReadKey();
}
}
}