public static void Initialize() { UserGameMonitor config = new UserGameMonitor(); config.LoadConfiguration(); BotConfiguration.AddConfigurable(config); if (enabled) { userGames = SerializationIO.LoadObjectFromFile <Dictionary <ulong, List <string> > > (Program.dataPath + fileName + Program.gitHubIgnoreType); if (userGames == null) { userGames = new Dictionary <ulong, List <string> > (); } Program.discordClient.UserUpdated += (before, after) => { try { if (!UserConfiguration.GetSetting <bool> (after.Id, "AllowSnooping")) { return(Task.CompletedTask); } string gameName = after.Game.HasValue ? after.Game.Value.Name.ToString().ToUpper() : null; AddGame(after, gameName); } catch (Exception e) { Logging.Log(Logging.LogType.EXCEPTION, e.Message + " - " + e.StackTrace); } return(Task.CompletedTask); }; } }
public async Task Initialize(DateTime time) { LoadConfiguration(); BotConfiguration.AddConfigurable(this); while (Utility.GetServer() == null) { await Task.Delay(1000); } IEnumerable <SocketGuildUser> users = Utility.GetServer().Users; birthdays = new List <Date> (); foreach (SocketGuildUser u in users) { try { // Heres to hoping no user ever has the ID 0. Date date = UserConfiguration.GetSetting <Date> (u.Id, "Birthday"); if (date != null) { birthdays.Add(date); } } catch (Exception f**k) { Logging.Log(Logging.LogType.EXCEPTION, f**k.Message); } } }
public Task Initialize(DateTime time) { LoadConfiguration(); BotConfiguration.AddConfigurable(this); Load(); return(Task.CompletedTask); }
public static void InitializeData() { Voice configurable = new Voice(); configurable.LoadConfiguration(); BotConfiguration.AddConfigurable(configurable); PostConnectInit(); }
public static void Initialize() { LoadData(); Permissions permissions = new Permissions(); permissions.LoadConfiguration(); BotConfiguration.AddConfigurable(permissions); }
public async Task Initialize(DateTime time) { await Task.Delay(10000); LoadConfiguration(); BotConfiguration.AddConfigurable(this); Program.discordClient.MessageReceived += DiscordClient_MessageReceived; // Eh whatever OnHourPassed(DateTime.Now); }
public async Task Initialize(DateTime time) { LoadConfiguration(); BotConfiguration.AddConfigurable(this); userActivity = SerializationIO.LoadObjectFromFile <Dictionary <ulong, DateTime> > (Program.dataPath + activityFileName + Program.gitHubIgnoreType); if (userActivity == null) { userActivity = new Dictionary <ulong, DateTime> (); } await Booted(); }
public Clock() { LoadConfiguration(); BotConfiguration.AddConfigurable(this); timeThread = new Thread(new ThreadStart(Initialize)); timeThread.Start(); while (!timeThread.IsAlive) { Logging.Log(Logging.LogType.BOT, "Initializing clock thread.."); } Thread.Sleep(1); }
public Task Initialize(DateTime time) { LoadConfiguration(); BotConfiguration.AddConfigurable(this); LoadData(); if (joinDate == null) { joinDate = new Dictionary <ulong, Youngling> (); } return(Task.CompletedTask); }
public static void Initialize() { Encryption enc = new Encryption(); enc.LoadConfiguration(); BotConfiguration.AddConfigurable(enc); while (!DoEncryptionCheck()) { Console.WriteLine("!WARNING! - ENCRYPTION FAILED TO SYNCRONIZE INPUT AND RESULT, THIS WILL HINDER FILES FROM LOADING CORRECTLY. CONTACT DEVELOPER IMMIDIATELY IF THIS OCCURS IN RELEASE VERSION. WRITE \"continue\" TO IGNORE."); if (Console.ReadLine() == "continue") { break; } } }
public StreamingMonitor() { LoadConfiguration(); BotConfiguration.AddConfigurable(this); Program.discordClient.UserUpdated += (before, after) => { if (before.Game.HasValue && before.Game.Value.StreamType == StreamType.NotStreaming) { if (after.Game.HasValue && after.Game.Value.StreamType != StreamType.NotStreaming) { TestAndAnnounceIf(after.Id, after.Game.Value); } } return(Task.CompletedTask); }; }
public override void Initialize() { base.Initialize(); LoadConfiguration(); BotConfiguration.AddConfigurable(this); Program.discordClient.UserJoined += (user) => { if (autoAddOnJoin) { try { Random random = new Random(); SocketRole color = Utility.GetServer().Roles.Where(x => allowed.Contains(x.Name)).ElementAt(random.Next(0, allowed.Length)); Utility.SecureAddRole(user, color); } catch (Exception e) { Logging.Log(e); } } return(Task.CompletedTask); }; }
public Karma() { LoadConfiguration(); BotConfiguration.AddConfigurable(this); data = SerializationIO.LoadObjectFromFile <Data> (Program.dataPath + karmaFileName + Program.gitHubIgnoreType); if (data == null) { data = new Data(); } Program.discordClient.ReactionAdded += async(message, channel, reaction) => { IMessage iMessage = await channel.GetMessageAsync(message.Id); if (reaction.Emote.Name == upvote) { ChangeKarma(iMessage, reaction.UserId, 1); } else if (reaction.Emote.Name == downvote) { ChangeKarma(iMessage, reaction.UserId, -1); } }; Program.discordClient.ReactionRemoved += async(message, channel, reaction) => { IMessage iMessage = await channel.GetMessageAsync(message.Id); if (reaction.Emote.Name == upvote) { ChangeKarma(iMessage, reaction.UserId, -1); } else if (reaction.Emote.Name == downvote) { ChangeKarma(iMessage, reaction.UserId, 1); } }; }
public async Task Initialize(DateTime time) { LoadConfiguration(); BotConfiguration.AddConfigurable(this); Data loadedData = SerializationIO.LoadObjectFromFile <Data> (Program.dataPath + dataFileName + Program.gitHubIgnoreType); votes = loadedData.votes; games = loadedData.games; votingMessageID = loadedData.votingMessageID; joinMessageID = loadedData.joinMessageID; allGames = loadedData.allGames; status = loadedData.status; weekIndex = loadedData.weekIndex; if (allGames == null) { allGames = new List <Game> (); } while (Utility.GetServer() == null) { await Task.Delay(1000); } if (status == WeeklyEventStatus.Waiting && (int)DateTime.Now.DayOfWeek < (int)voteEndDay) { BeginNewVote(); } Program.discordClient.ReactionAdded += async(message, channel, reaction) => { OnReactionChanged(message, channel, reaction, true); }; Program.discordClient.ReactionRemoved += async(message, channel, reaction) => { OnReactionChanged(message, channel, reaction, false); }; }
public override void Initialize() { base.Initialize(); LoadConfiguration(); BotConfiguration.AddConfigurable(this); }
public async Task Start(string [] args) { dataPath = AppContext.BaseDirectory + "/data/"; dataPath = dataPath.Replace('\\', '/'); InitializeDirectories(); Logging.Log(Logging.LogType.BOT, "Initializing bot.. Datapath: " + dataPath); BotConfiguration.Initialize(); Encryption.Initialize(); BotConfiguration.AddConfigurable(this); LoadConfiguration(); discordClient = new DiscordSocketClient(); messageControl = new MessageControl(); karma = new Karma(); new StreamingMonitor(); LegalJunk.Initialize(); Logging.Log(Logging.LogType.BOT, "Loading data.."); InitializeCommands(); UserConfiguration.Initialize(); InviteHandler.Initialize(); CommandChain.Initialize(); Permissions.Initialize(); AutoCommands.Initialize(); clock = new Clock(); InitializeData(); UserGameMonitor.Initialize(); bootedTime = DateTime.Now.AddSeconds(BOOT_WAIT_TIME); Logging.Log(Logging.LogType.BOT, "Setting up events.."); discordClient.MessageReceived += async(e) => { Logging.Log(Logging.LogType.CHAT, Utility.GetChannelName(e) + " says: " + e.Content); bool hideTrigger = false; if (e.Content.Length > 0 && ContainsCommandTrigger(e.Content, out hideTrigger)) { FindAndExecuteCommand(e, e.Content, commands, 0, true, true); } if (e.Author.Id != discordClient.CurrentUser.Id) { FindPhraseAndRespond(e); AutoCommands.RunEvent(AutoCommands.Event.MessageRecieved, e.Content, e.Channel.Id.ToString()); } if (e.Content.Length > 0 && hideTrigger) { e.DeleteAsync(); allowedDeletedMessages.Add(e.Content); } }; discordClient.MessageUpdated += async(cache, message, channel) => { Logging.Log(Logging.LogType.CHAT, "Message edited: " + Utility.GetChannelName(message as SocketMessage) + " " + message.Content); AutoCommands.RunEvent(AutoCommands.Event.MessageDeleted, message.Content, message.Channel.Id.ToString()); }; discordClient.MessageDeleted += async(cache, channel) => { IMessage message = await cache.GetOrDownloadAsync(); Logging.Log(Logging.LogType.CHAT, "Message deleted: " + Utility.GetChannelName(channel as SocketGuildChannel)); AutoCommands.RunEvent(AutoCommands.Event.MessageDeleted, channel.Id.ToString()); }; discordClient.UserJoined += async(e) => { Younglings.OnUserJoined(e); RestInviteMetadata possibleInvite = await InviteHandler.FindInviter(); Logging.Log(Logging.LogType.BOT, "User " + e.Username + " joined."); AutoCommands.RunEvent(AutoCommands.Event.UserJoined, e.Id.ToString()); SocketGuildUser inviter; if (possibleInvite != null) { inviter = Utility.GetServer().GetUser(possibleInvite.Inviter.Id); string joinMessage = Utility.SelectRandom(onUserJoinFromInviteMessage); messageControl.SendMessage(Utility.GetMainChannel() as SocketTextChannel, joinMessage.Replace("{USERNAME}", Utility.GetUserName(e)).Replace("{INVITERNAME}", Utility.GetUserName(inviter)), true); } else { string joinMessage = Utility.SelectRandom(onUserJoinMessage); messageControl.SendMessage(Utility.GetMainChannel() as SocketTextChannel, joinMessage.Replace("{USERNAME}", Utility.GetUserName(e)), true); } string [] welcomeMessage = SerializationIO.LoadTextFile(dataPath + "welcomemessage" + gitHubIgnoreType); string combined = ""; for (int i = 0; i < welcomeMessage.Length; i++) { combined += welcomeMessage [i] + "\n"; } await messageControl.SendMessage(e, combined); }; discordClient.UserLeft += (e) => { string leftMessage = Utility.SelectRandom(onUserLeaveMessage); Logging.Log(Logging.LogType.BOT, "User " + e.Username + " left."); AutoCommands.RunEvent(AutoCommands.Event.UserLeft, e.Id.ToString()); if (automaticLeftReason.ContainsKey(e.Id)) { leftMessage = $"**{Utility.GetUserName (e)}** left - " + automaticLeftReason [e.Id]; automaticLeftReason.Remove(e.Id); } messageControl.SendMessage(Utility.GetMainChannel() as SocketTextChannel, leftMessage.Replace("{USERNAME}", Utility.GetUserName(e)), true); return(Task.CompletedTask); }; discordClient.UserVoiceStateUpdated += async(user, before, after) => { Logging.Log(Logging.LogType.BOT, "User voice updated: " + user.Username); SocketGuild guild = (user as SocketGuildUser).Guild; if (after.VoiceChannel != null) { Voice.allVoiceChannels [after.VoiceChannel.Id].OnUserJoined(user as SocketGuildUser); } if (before.VoiceChannel == null && after.VoiceChannel != null) { AutoCommands.RunEvent(AutoCommands.Event.JoinedVoice, user.Id.ToString(), after.VoiceChannel.Id.ToString()); } if (before.VoiceChannel != null && after.VoiceChannel == null) { AutoCommands.RunEvent(AutoCommands.Event.LeftVoice, user.Id.ToString(), before.VoiceChannel.Id.ToString()); } await Voice.OnUserUpdated(guild, before.VoiceChannel, after.VoiceChannel); return; }; discordClient.GuildMemberUpdated += async(before, after) => { if ((before as SocketGuildUser).Nickname != (after as SocketGuildUser).Nickname) { MentionNameChange(before, after); } }; discordClient.UserUpdated += (before, after) => { if (before.Username != after.Username && (after as SocketGuildUser).Nickname == "") { MentionNameChange(before as SocketGuildUser, after as SocketGuildUser); } return(Task.CompletedTask); }; discordClient.UserBanned += (e, guild) => { SocketChannel channel = Utility.GetMainChannel(); if (channel == null) { return(Task.CompletedTask); } string banMessage = Utility.SelectRandom(onUserBannedMessage); messageControl.SendMessage(channel as SocketTextChannel, banMessage.Replace("{USERNAME}", Utility.GetUserName(e as SocketGuildUser)), true); return(Task.CompletedTask); }; discordClient.UserUnbanned += (e, guild) => { SocketChannel channel = Utility.GetMainChannel(); if (channel == null) { return(Task.CompletedTask); } string unbannedMessage = Utility.SelectRandom(onUserUnbannedMessage); messageControl.SendMessage(channel as SocketTextChannel, unbannedMessage.Replace("{USERNAME}", Utility.GetUserName(e as SocketGuildUser)), true); return(Task.CompletedTask); }; discordClient.Ready += () => { Logging.Log(Logging.LogType.BOT, "Bot is ready and running!"); return(Task.CompletedTask); }; string token = ""; try { token = SerializationIO.LoadTextFile(dataPath + "bottoken" + gitHubIgnoreType)[0]; }catch (Exception e) { Logging.Log(Logging.LogType.CRITICAL, "Bottoken not found, please create a file at <botroot>/data/bottoken.botproperty and insert bottoken there. " + e.Message); } Logging.Log(Logging.LogType.BOT, "Connecting to Discord.."); await discordClient.LoginAsync(TokenType.Bot, token); await discordClient.StartAsync(); BotConfiguration.PostInit(); await Utility.AwaitFullBoot(); try { if (args.Length > 0 && args [0] == "true" && onPatchedAnnounceChannel != 0) { using (HttpClient client = new HttpClient()) { string changelog = await client.GetStringAsync(AutoPatcher.url + "changelog.txt"); string version = await client.GetStringAsync(AutoPatcher.url + "version.txt"); string total = $"Succesfully installed new patch, changelog for {version}:\n{changelog}"; SocketGuildChannel patchNotesChannel = Utility.GetServer().GetChannel(onPatchedAnnounceChannel); if (patchNotesChannel != null) { messageControl.SendMessage(patchNotesChannel as ISocketMessageChannel, total, true, "```"); } } } } catch (Exception e) { Logging.Log(e); } BakeQuickCommands(); await Task.Delay(-1); }
public virtual void Initialize() { LoadConfiguration(); BotConfiguration.AddConfigurable(this); }