private static void Main() { Console.OutputEncoding = Encoding.Unicode; try { File.WriteAllText("data/config_example.json", JsonConvert.SerializeObject(new Configuration(), Formatting.Indented)); if (!File.Exists("data/config.json")) { File.Copy("data/config_example.json", "data/config.json"); } File.WriteAllText("credentials_example.json", JsonConvert.SerializeObject(new Credentials(), Formatting.Indented)); } catch { Console.WriteLine("Failed writing credentials_example.json or data/config_example.json"); } try { Config = JsonConvert.DeserializeObject <Configuration>(File.ReadAllText("data/config.json")); Config.Quotes = JsonConvert.DeserializeObject <List <Quote> >(File.ReadAllText("data/quotes.json")); Config.PokemonTypes = JsonConvert.DeserializeObject <List <PokemonType> >(File.ReadAllText("data/PokemonTypes.json")); } catch (Exception ex) { Console.WriteLine("Failed loading configuration."); Console.WriteLine(ex); Console.ReadKey(); return; } try { //load credentials from credentials.json Creds = JsonConvert.DeserializeObject <Credentials>(File.ReadAllText("credentials.json")); } catch (Exception ex) { Console.WriteLine($"Failed to load stuff from credentials.json, RTFM\n{ex.Message}"); Console.ReadKey(); return; } //if password is not entered, prompt for password if (string.IsNullOrWhiteSpace(Creds.Token)) { Console.WriteLine("Token blank. Please enter your bot's token:\n"); Creds.Token = Console.ReadLine(); } Console.WriteLine(string.IsNullOrWhiteSpace(Creds.GoogleAPIKey) ? "No google api key found. You will not be able to use music and links won't be shortened." : "Google API key provided."); Console.WriteLine(string.IsNullOrWhiteSpace(Creds.TrelloAppKey) ? "No trello appkey found. You will not be able to use trello commands." : "Trello app key provided."); Console.WriteLine(Config.ForwardMessages != true ? "Not forwarding messages." : "Forwarding private messages to owner."); Console.WriteLine(string.IsNullOrWhiteSpace(Creds.SoundCloudClientID) ? "No soundcloud Client ID found. Soundcloud streaming is disabled." : "SoundCloud streaming enabled."); Console.WriteLine(string.IsNullOrWhiteSpace(Creds.OsuAPIKey) ? "No osu! api key found. Song & top score lookups will not work. User lookups still available." : "osu! API key provided."); BotMention = $"<@{Creds.BotId}>"; //create new discord client and log Client = new DiscordClient(new DiscordConfigBuilder() { MessageCacheSize = 10, ConnectionTimeout = int.MaxValue, LogLevel = LogSeverity.Warning, LogHandler = (s, e) => Console.WriteLine($"Severity: {e.Severity}" + $"ExceptionMessage: {e.Exception?.Message ?? "-"}" + $"Message: {e.Message}"), }); //create a command service var commandService = new CommandService(new CommandServiceConfigBuilder { AllowMentionPrefix = false, CustomPrefixHandler = m => 0, HelpMode = HelpMode.Disabled, ErrorHandler = async(s, e) => { if (e.ErrorType != CommandErrorType.BadPermissions) { return; } if (string.IsNullOrWhiteSpace(e.Exception?.Message)) { return; } try { await e.Channel.SendMessage(e.Exception.Message).ConfigureAwait(false); } catch { } } }); //add command service Client.AddService <CommandService>(commandService); //create module service var modules = Client.AddService <ModuleService>(new ModuleService()); //add audio service Client.AddService <AudioService>(new AudioService(new AudioServiceConfigBuilder() { Channels = 2, EnableEncryption = false, Bitrate = 128, })); //install modules modules.Add(new HelpModule(), "Help", ModuleFilter.None); modules.Add(new AdministrationModule(), "Administration", ModuleFilter.None); modules.Add(new UtilityModule(), "Utility", ModuleFilter.None); modules.Add(new PermissionModule(), "Permissions", ModuleFilter.None); modules.Add(new Conversations(), "Conversations", ModuleFilter.None); modules.Add(new GamblingModule(), "Gambling", ModuleFilter.None); modules.Add(new GamesModule(), "Games", ModuleFilter.None); #if !WIZ_RELEASE modules.Add(new MusicModule(), "Music", ModuleFilter.None); #endif modules.Add(new SearchesModule(), "Searches", ModuleFilter.None); modules.Add(new NSFWModule(), "NSFW", ModuleFilter.None); modules.Add(new ClashOfClansModule(), "ClashOfClans", ModuleFilter.None); modules.Add(new PokemonModule(), "Pokegame", ModuleFilter.None); modules.Add(new TranslatorModule(), "Translator", ModuleFilter.None); modules.Add(new CustomReactionsModule(), "Customreactions", ModuleFilter.None); if (!string.IsNullOrWhiteSpace(Creds.TrelloAppKey)) { modules.Add(new TrelloModule(), "Trello", ModuleFilter.None); } //run the bot Client.ExecuteAndWait(async() => { await Task.Run(() => { Console.WriteLine("Specific config started initializing."); var x = SpecificConfigurations.Default; Console.WriteLine("Specific config done initializing."); }); await PermissionsHandler.Initialize(); try { await Client.Connect(Creds.Token, TokenType.Bot).ConfigureAwait(false); } catch (Exception ex) { Console.WriteLine($"Token is wrong. Don't set a token if you don't have an official BOT account."); Console.WriteLine(ex); Console.ReadKey(); return; } #if WIZ_RELEASE await Task.Delay(300000).ConfigureAwait(false); #else await Task.Delay(1000).ConfigureAwait(false); #endif Console.WriteLine("-----------------"); Console.WriteLine(await WizStats.Instance.GetStats().ConfigureAwait(false)); Console.WriteLine("-----------------"); OwnerPrivateChannels = new List <Channel>(Creds.OwnerIds.Length); foreach (var id in Creds.OwnerIds) { try { OwnerPrivateChannels.Add(await Client.CreatePrivateChannel(id).ConfigureAwait(false)); } catch { Console.WriteLine($"Failed creating private channel with the owner {id} listed in credentials.json"); } } Client.ClientAPI.SendingRequest += (s, e) => { var request = e.Request as Discord.API.Client.Rest.SendMessageRequest; if (request == null) { return; } // meew0 is magic request.Content = request.Content?.Replace("@everyone", "@everyοne").Replace("@here", "@һere") ?? "_error_"; if (string.IsNullOrWhiteSpace(request.Content)) { e.Cancel = true; } }; #if WIZ_RELEASE Client.ClientAPI.SentRequest += (s, e) => { Console.WriteLine($"[Request of type {e.Request.GetType()} sent in {e.Milliseconds}]"); var request = e.Request as Discord.API.Client.Rest.SendMessageRequest; if (request == null) { return; } Console.WriteLine($"[Content: { request.Content }"); }; #endif WizBot.Ready = true; WizBot.OnReady(); Console.WriteLine("Ready!"); //reply to personal messages and forward if enabled. Client.MessageReceived += Client_MessageReceived; }); Console.WriteLine("Exiting..."); Console.ReadKey(); }
private static void Main() { Console.OutputEncoding = Encoding.Unicode; //var lines = File.ReadAllLines("data/input.txt"); //HashSet<dynamic> list = new HashSet<dynamic>(); //for (int i = 0; i < lines.Length; i += 3) { // dynamic obj = new JArray(); // obj.Text = lines[i]; // obj.Author = lines[i + 1]; // if (obj.Author.StartsWith("-")) // obj.Author = obj.Author.Substring(1, obj.Author.Length - 1).Trim(); // list.Add(obj); //} //File.WriteAllText("data/quotes.json", Newtonsoft.Json.JsonConvert.SerializeObject(list, Formatting.Indented)); //Console.ReadKey(); // generate credentials example so people can know about the changes i make try { File.WriteAllText("data/config_example.json", JsonConvert.SerializeObject(new Configuration(), Formatting.Indented)); if (!File.Exists("data/config.json")) { File.Copy("data/config_example.json", "data/config.json"); } File.WriteAllText("credentials_example.json", JsonConvert.SerializeObject(new Credentials(), Formatting.Indented)); } catch { Console.WriteLine("Failed writing credentials_example.json or data/config_example.json"); } try { Config = JsonConvert.DeserializeObject <Configuration>(File.ReadAllText("data/config.json")); Config.Quotes = JsonConvert.DeserializeObject <List <Quote> >(File.ReadAllText("data/quotes.json")); Config.PokemonTypes = JsonConvert.DeserializeObject <List <PokemonType> >(File.ReadAllText("data/PokemonTypes.json")); } catch (Exception ex) { Console.WriteLine("Failed loading configuration."); Console.WriteLine(ex); Console.ReadKey(); return; } try { //load credentials from credentials.json Creds = JsonConvert.DeserializeObject <Credentials>(File.ReadAllText("credentials.json")); } catch (Exception ex) { Console.WriteLine($"Failed to load stuff from credentials.json, RTFM\n{ex.Message}"); Console.ReadKey(); return; } //if password is not entered, prompt for password if (string.IsNullOrWhiteSpace(Creds.Password) && string.IsNullOrWhiteSpace(Creds.Token)) { Console.WriteLine("Password blank. Please enter your password:\n"); Creds.Password = Console.ReadLine(); } Console.WriteLine(string.IsNullOrWhiteSpace(Creds.GoogleAPIKey) ? "No google api key found. You will not be able to use music and links won't be shortened." : "Google API key provided."); Console.WriteLine(string.IsNullOrWhiteSpace(Creds.TrelloAppKey) ? "No trello appkey found. You will not be able to use trello commands." : "Trello app key provided."); Console.WriteLine(Config.ForwardMessages != true ? "Not forwarding messages." : "Forwarding private messages to owner."); Console.WriteLine(string.IsNullOrWhiteSpace(Creds.SoundCloudClientID) ? "No soundcloud Client ID found. Soundcloud streaming is disabled." : "SoundCloud streaming enabled."); BotMention = $"<@{Creds.BotId}>"; //create new discord client and log Client = new DiscordClient(new DiscordConfigBuilder() { MessageCacheSize = 10, ConnectionTimeout = 120000, LogLevel = LogSeverity.Warning, LogHandler = (s, e) => Console.WriteLine($"Severity: {e.Severity}" + $"Message: {e.Message}" + $"ExceptionMessage: {e.Exception?.Message ?? "-"}"), }); //create a command service var commandService = new CommandService(new CommandServiceConfigBuilder { AllowMentionPrefix = false, CustomPrefixHandler = m => 0, HelpMode = HelpMode.Disabled, ErrorHandler = async(s, e) => { if (e.ErrorType != CommandErrorType.BadPermissions) { return; } if (string.IsNullOrWhiteSpace(e.Exception?.Message)) { return; } try { await e.Channel.SendMessage(e.Exception.Message).ConfigureAwait(false); } catch { } } }); //reply to personal messages and forward if enabled. Client.MessageReceived += Client_MessageReceived; //add command service Client.AddService <CommandService>(commandService); //create module service var modules = Client.AddService <ModuleService>(new ModuleService()); //add audio service Client.AddService <AudioService>(new AudioService(new AudioServiceConfigBuilder() { Channels = 2, EnableEncryption = false, Bitrate = 128, })); //install modules modules.Add(new AdministrationModule(), "Administration", ModuleFilter.None); modules.Add(new HelpModule(), "Help", ModuleFilter.None); modules.Add(new PermissionModule(), "Permissions", ModuleFilter.None); modules.Add(new Conversations(), "Conversations", ModuleFilter.None); modules.Add(new GamblingModule(), "Gambling", ModuleFilter.None); modules.Add(new GamesModule(), "Games", ModuleFilter.None); modules.Add(new MusicModule(), "Music", ModuleFilter.None); modules.Add(new SearchesModule(), "Searches", ModuleFilter.None); modules.Add(new NSFWModule(), "NSFW", ModuleFilter.None); modules.Add(new ClashOfClansModule(), "ClashOfClans", ModuleFilter.None); modules.Add(new PokemonModule(), "Pokegame", ModuleFilter.None); modules.Add(new TranslatorModule(), "Translator", ModuleFilter.None); modules.Add(new CustomReactionsModule(), "Customreactions", ModuleFilter.None); if (!string.IsNullOrWhiteSpace(Creds.TrelloAppKey)) { modules.Add(new TrelloModule(), "Trello", ModuleFilter.None); } //run the bot Client.ExecuteAndWait(async() => { try { if (string.IsNullOrWhiteSpace(Creds.Token)) { await Client.Connect(Creds.Username, Creds.Password).ConfigureAwait(false); } else { await Client.Connect(Creds.Token).ConfigureAwait(false); IsBot = true; } } catch (Exception ex) { if (string.IsNullOrWhiteSpace(Creds.Token)) { Console.WriteLine($"Probably wrong EMAIL or PASSWORD."); } else { Console.WriteLine($"Token is wrong. Don't set a token if you don't have an official BOT account."); } Console.WriteLine(ex); Console.ReadKey(); return; } await Task.Delay(1000).ConfigureAwait(false); Console.WriteLine("-----------------"); Console.WriteLine(await NadekoStats.Instance.GetStats().ConfigureAwait(false)); Console.WriteLine("-----------------"); try { OwnerPrivateChannel = await Client.CreatePrivateChannel(Creds.OwnerIds[0]).ConfigureAwait(false); } catch { Console.WriteLine("Failed creating private channel with the first owner listed in credentials.json"); } Client.ClientAPI.SendingRequest += (s, e) => { var request = e.Request as Discord.API.Client.Rest.SendMessageRequest; if (request == null) { return; } // meew0 is magic request.Content = request.Content?.Replace("@everyone", "@everyοne").Replace("@here", "@һere") ?? "_error_"; if (string.IsNullOrWhiteSpace(request.Content)) { e.Cancel = true; } }; PermissionsHandler.Initialize(); NadekoBot.Ready = true; }); Console.WriteLine("Exiting..."); Console.ReadKey(); }
private static void Main() { Console.OutputEncoding = Encoding.Unicode; Console.Title = "Midnight Bot | Starting..."; try { List <_Models.JSONModels.APIConfig> apis = new List <_Models.JSONModels.APIConfig>() { { new _Models.JSONModels.APIConfig { Names = new List <string>() { "randomcat", "meow" }, QueryReplacements = new Dictionary <string, string>() { { @".*", "" } }, URL = "http://www.random.cat/meow", ResponseHandling = Tuple.Create("JSON", "file"), URLSuffix = "", AllowEmpty = true } }, { new _Models.JSONModels.APIConfig { Names = new List <string>() { "i", "image" }, } } }; File.WriteAllText("data/apis.json", JsonConvert.SerializeObject(apis, Formatting.Indented)); File.WriteAllText("data/config_example.json", JsonConvert.SerializeObject(new Configuration(), Formatting.Indented)); if (!File.Exists("data/config.json")) { File.Copy("data/config_example.json", "data/config.json"); } File.WriteAllText("credentials_example.json", JsonConvert.SerializeObject(new Credentials(), Formatting.Indented)); } catch { Console.WriteLine("Failed writing credentials_example.json or data/config_example.json"); } try { Config = JsonConvert.DeserializeObject <Configuration> (File.ReadAllText("data/config.json", Encoding.UTF8)); Config.Quotes = JsonConvert.DeserializeObject <List <Quote> > (File.ReadAllText("data/quotes.json")); Config.PokemonTypes = JsonConvert.DeserializeObject <List <PokemonType> > (File.ReadAllText("data/PokemonTypes.json")); } catch (Exception ex) { Console.WriteLine("Einstellungen konnten nicht geladen werden."); Console.WriteLine(ex); Console.ReadKey(); return; } try { //load credentials from credentials.json Creds = JsonConvert.DeserializeObject <Credentials> (File.ReadAllText("credentials.json")); } catch (Exception ex) { Console.WriteLine($"Failed to load stuff from credentials.json, RTFM\n{ex.Message}"); Console.ReadKey(); return; } //if password is not entered, prompt for password if (string.IsNullOrWhiteSpace(Creds.Token)) { Console.WriteLine("Kein Token gesetzt. Bitte gib deinen Bot-Token ein:\n"); Creds.Token = Console.ReadLine(); } Console.WriteLine(string.IsNullOrWhiteSpace(GetRndGoogleAPIKey()) ? "Kein Google Api Key gefunden. Du kannst keine Musik benutzen und Links werden nicht gekürzt." : "Google API key vorhanden."); Console.WriteLine(string.IsNullOrWhiteSpace(Creds.TrelloAppKey) ? "Kein trello appkey gefunden. Du kannst keine trello Befehle benutzen." : "Trello app key vorhanden."); Console.WriteLine(Config.ForwardMessages != true ? "Keine Weiterleitung von Nachrichten." : "Nachrichten werden weitergeleitet."); Console.WriteLine(string.IsNullOrWhiteSpace(Creds.SoundCloudClientID) ? "Keine Soundcloud Client ID gefunden. Soundcloud Streaming ist deaktiviert." : "SoundCloud Streaming aktiviert."); Console.WriteLine(string.IsNullOrWhiteSpace(Creds.OsuAPIKey) ? "Kein osu! API Key gefunden. Song & Top Score Suche werden nicht funktionieren. Benutzer Suche ist verwendbar." : "osu! API Key gefunden."); BotMention = $"<@{Creds.BotId}>"; //create new discord client and log Client = new DiscordClient(new DiscordConfigBuilder() { MessageCacheSize = 10, ConnectionTimeout = 120000, LogLevel = LogSeverity.Warning, LogHandler = (s, e) => Console.WriteLine($"Severity: {e.Severity}" + $"Message: {e.Message}" + $"ExceptionMessage: {e.Exception?.Message ?? "-"}"), }); //create a command service var commandService = new CommandService(new CommandServiceConfigBuilder { AllowMentionPrefix = false, CustomPrefixHandler = m => 0, HelpMode = HelpMode.Disabled, ErrorHandler = async(s, e) => { if (e.ErrorType != CommandErrorType.BadPermissions) { return; } if (string.IsNullOrWhiteSpace(e.Exception?.Message)) { return; } try { await e.Channel.SendMessage(e.Exception.Message).ConfigureAwait(false); } catch { } } }); //reply to personal messages and forward if enabled. Client.MessageReceived += Client_MessageReceived; //add command service Client.AddService <CommandService> (commandService); //create module service var modules = Client.AddService <ModuleService> (new ModuleService()); //add audio service Client.AddService <AudioService> (new AudioService(new AudioServiceConfigBuilder() { Channels = 2, EnableEncryption = false, Bitrate = 128, })); AppDomain.CurrentDomain.ProcessExit += (s, e) => { MidnightBot.shutdownGracefully(); }; //install modules modules.Add(new HelpModule(), "Help", ModuleFilter.None); modules.Add(new AdministrationModule(), "Administration", ModuleFilter.None); modules.Add(new UtilityModule(), "Utility", ModuleFilter.None); modules.Add(new PermissionModule(), "Permissions", ModuleFilter.None); modules.Add(new Conversations(), "Conversations", ModuleFilter.None); modules.Add(new GamblingModule(), "Gambling", ModuleFilter.None); modules.Add(new GamesModule(), "Games", ModuleFilter.None); modules.Add(new LevelModule(), "Level", ModuleFilter.None); modules.Add(new MusicModule(), "Music", ModuleFilter.None); modules.Add(new SearchesModule(), "Searches", ModuleFilter.None); modules.Add(new ExtraModule(), "Extra", ModuleFilter.None); modules.Add(new PokemonModule(), "Pokegame", ModuleFilter.None); modules.Add(new TranslatorModule(), "Translator", ModuleFilter.None); modules.Add(new MemeModule(), "Memes", ModuleFilter.None); modules.Add(new NSFWModule(), "NSFW", ModuleFilter.None); modules.Add(new SoundsModule(), "Sounds", ModuleFilter.None); modules.Add(new ClashOfClansModule(), "ClashOfClans", ModuleFilter.None); modules.Add(new CustomReactionsModule(), "Customreactions", ModuleFilter.None); if (!string.IsNullOrWhiteSpace(Creds.TrelloAppKey)) { modules.Add(new TrelloModule(), "Trello", ModuleFilter.None); } //run the bot Client.ExecuteAndWait(async() => { Console.WriteLine("Bitte warte während der Bot startet..."); try { await Client.Connect(Creds.Token).ConfigureAwait(false); } catch (Exception ex) { Console.WriteLine($"Token ist fehlerhaft. Setze keinen Token wenn du keinen offiziellen BOT Account bestitzt."); Console.WriteLine(ex); Console.ReadKey(); return; } //Console.Write("Startvorgang dauert 10 Sekunden: "); //for(int i=10;i!=0;i--) //{ // Console.Write(i + " "); // await Task.Delay(1000).ConfigureAwait(false); //} //Console.WriteLine(); //await Task.Delay(10000).ConfigureAwait(false); Console.WriteLine("-----------------"); Console.WriteLine(await MidnightStats.Instance.GetStats().ConfigureAwait(false)); Console.WriteLine("-----------------"); OwnerPrivateChannels = new List <Channel>(Creds.OwnerIds.Length); foreach (var id in Creds.OwnerIds) { try { OwnerPrivateChannels.Add(await Client.CreatePrivateChannel(id).ConfigureAwait(false)); } catch { Console.WriteLine($"Konnte keinen privaten Channel mit dem Owner, welcher mit der ID {id} in der credentials.json gelistet ist"); } } //foreach (var ch in MidnightBot.Client.Servers.Select (s => s.DefaultChannel)) //{ // await ch.SendMessage ("`Hallo. Ich bin wieder da!`"); //} Client.ClientAPI.SendingRequest += (s, e) => { var request = e.Request as Discord.API.Client.Rest.SendMessageRequest; if (request == null) { return; } // meew0 is magic request.Content = request.Content?.Replace("@everyone", "@everyοne").Replace("@here", "@һere") ?? "_error_"; if (string.IsNullOrWhiteSpace(request.Content)) { e.Cancel = true; } }; //await Task.Delay(90000); PermissionsHandler.Initialize(); Console.Title = "Midnight Bot | Connected"; Console.WriteLine("Bot ist initialisiert."); MidnightBot.Ready = true; MidnightBot.OnReady(); }); Console.WriteLine("Beende..."); Console.ReadKey(); }