Example #1
0
        public static void ChangeKarma(IMessage message, ulong giver, int change)
        {
            if (giver == message.Author.Id)
            {
                return;
            }

            if (!data.karmaCollection.ContainsKey(message.Author.Id))
            {
                data.karmaCollection.Add(message.Author.Id, 0);
            }
            data.karmaCollection [message.Author.Id] += change;

            if (!data.trackedMessages.ContainsKey(message.Id))
            {
                data.trackedMessages.Add(message.Id, 0);
            }
            data.trackedMessages [message.Id] += change;

            if (data.trackedMessages [message.Id] >= upvotesToQuote && upvotesToQuote > 0)
            {
                CQuote.AddQuoteFromMessage(message);
            }
            if (data.trackedMessages [message.Id] <= downvotesToDelete && downvotesToDelete < 0)     // Could be in an else-if, but it felt wrong for some reason.
            {
                DeleteMessage(message);
            }

            SerializationIO.SaveObjectToFile(Program.dataPath + karmaFileName + Program.gitHubIgnoreType, data);
        }
Example #2
0
        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);
                };
            }
        }
Example #3
0
 private static void Load()
 {
     strikes = SerializationIO.LoadObjectFromFile <Dictionary <ulong, Strike> > (Program.dataPath + strikeDataPath + Program.gitHubIgnoreType);
     if (strikes == null)
     {
         strikes = new Dictionary <ulong, Strike> ();
     }
 }
Example #4
0
 private static void LoadData()
 {
     autocEvents = SerializationIO.LoadObjectFromFile <Dictionary <Event, AutocEvent> > (saveDataPath);
     if (autocEvents == null)
     {
         autocEvents = new Dictionary <Event, AutocEvent> ();
     }
 }
Example #5
0
 public static void LoadEvents()
 {
     upcomingEvents = SerializationIO.LoadObjectFromFile <List <Event> > (Program.dataPath + eventFileName + Program.gitHubIgnoreType);
     if (upcomingEvents == null)
     {
         upcomingEvents = new List <Event> ();
     }
 }
        public Task <Result> Execute(SocketUserMessage e, string header)
        {
            string filePath = Program.dataPath + AutomatedTextChannels.additionalHeaderPath;

            AutomatedTextChannels.AddHeaders(header);
            SerializationIO.SaveTextFile(filePath, header);

            return(TaskResult(header, "Succesfully added header to list of additional headers!"));
        }
Example #7
0
 public override void Initialize()
 {
     base.Initialize();
     quotes = SerializationIO.LoadObjectFromFile <List <string> > (Program.dataPath + "quotes" + Program.gitHubIgnoreType);
     if (quotes == null)
     {
         quotes = new List <string> ();
     }
 }
Example #8
0
 public static void LoadData()
 {
     allPermissions = SerializationIO.LoadObjectFromFile <Dictionary <ulong, PermissionSet> > (filePath);
     if (allPermissions == null)
     {
         allPermissions = new Dictionary <ulong, PermissionSet> ();
         SaveData();
     }
 }
Example #9
0
 public Task <Result> Execute(SocketUserMessage e, string path)
 {
     try {
         string text = SerializationIO.LoadTextFile(Program.dataPath + path).Singlify();
         return(TaskResult(text, text));
     } catch {
         return(TaskResult("", "Error - File could not be found."));
     }
 }
        public Task Initialize(DateTime time)
        {
            string filePath = Program.dataPath + additionalHeaderPath;

            if (File.Exists(filePath))
            {
                string[] additional = SerializationIO.LoadTextFile(filePath);
                AddHeaders(additional);
            }
            return(Task.CompletedTask);
        }
 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();
 }
Example #12
0
        public static async void CheckForPatch(bool ignoreAuto)
        {
            string basePath = AppContext.BaseDirectory + "/";

            if (!Directory.Exists(basePath + "/patcher/"))
            {
                Logging.Log(Logging.LogType.WARNING, "Patcher application not located dispite autopatching being activated.");
                return;
            }

            using (HttpClient client = new HttpClient()) {
                string localVersion = "";
                try {
                    localVersion = SerializationIO.LoadTextFile(basePath + "version.txt") [0];
                } catch { }

                string version = await client.GetStringAsync(url + "version.txt");

                if (localVersion != version)
                {
                    // A new patch is available.
                    try {
                        string changelog = await client.GetStringAsync(url + "changelog.txt");

                        changelog = $"Adminthulhu Bot Version {version} \n```{changelog}```";
                        SocketTextChannel announceChannel = Utility.GetServer().GetChannel(announcePatchAvailabilityChannelID) as SocketTextChannel;

                        if (announceChannel != null)
                        {
                            Program.messageControl.SendMessage(announceChannel as ISocketMessageChannel, changelog, true);
                        }

                        if (doAutoPatch && !ignoreAuto)
                        {
                            Patch();
                        }
                        else
                        {
                            try {
                                SocketTextChannel askChannel = Utility.GetServer().GetChannel(askToPatchChannelID) as SocketTextChannel;
                                Program.messageControl.AskQuestion(askChannel.Id, "A new patch for me has become available, should I install?", delegate() {
                                    Program.messageControl.SendMessage(askChannel, "Installing patch, please stand by..", true);
                                    Patch();
                                });
                            } catch (Exception e) {
                                Logging.Log(Logging.LogType.EXCEPTION, e.Message + " - " + e.StackTrace);
                            }
                        }
                    } catch (Exception e) {
                        Logging.Log(Logging.LogType.EXCEPTION, e + " - " + e.StackTrace);
                    }
                }
            }
        }
Example #13
0
        public static void Initialize()
        {
            userSettings = SerializationIO.LoadObjectFromFile <Dictionary <ulong, List <Setting> > > (Program.dataPath + settingsFileName + Program.gitHubIgnoreType);
            if (userSettings == null)
            {
                userSettings = new Dictionary <ulong, List <Setting> > ();
            }

            UserConfiguration config = new UserConfiguration();

            config.LoadConfiguration();
        }
Example #14
0
 public static void Initialize()
 {
     LoadSettings();
     if (settings == null)
     {
         settings = new Dictionary <string, object> ();
     }
     else
     {
         SerializationIO.SaveObjectToFile(Program.dataPath + settingsFileName + "_BACKUP" + Program.gitHubIgnoreType, settings, true, false);
     }
 }
Example #15
0
        public static AliasCollection Load()
        {
            AliasCollection collection = SerializationIO.LoadObjectFromFile <AliasCollection> (Program.dataPath + "aliasses.dat");

            if (collection == null)
            {
                return(new AliasCollection());
            }
            else
            {
                return(collection);
            }
        }
Example #16
0
        public static void LoadData()
        {
            data = SerializationIO.LoadObjectFromFile <Data> (Program.dataPath + dataFileName + Program.gitHubIgnoreType);
            if (data == null)
            {
                data = new Data();
            }

            foreach (CustomCommand cmd in data.customCommands)
            {
                CustomCommandSet.customSet.AddProceduralCommands(cmd);
            }
        }
Example #17
0
        public static Dictionary <string, int> Load()
        {
            Dictionary <string, int> collection = SerializationIO.LoadObjectFromFile <Dictionary <string, int> > (Program.dataPath + "scores" + Program.gitHubIgnoreType);

            if (collection == null)
            {
                return(new Dictionary <string, int> ());
            }
            else
            {
                return(collection);
            }
        }
Example #18
0
        public static PlayerGroups Load()
        {
            PlayerGroups groups = SerializationIO.LoadObjectFromFile <PlayerGroups> (Program.dataPath + "groups" + Program.gitHubIgnoreType);

            if (groups != null)
            {
                return(groups);
            }
            else
            {
                return(new PlayerGroups());
            }
        }
        public Task OnDayPassed(DateTime time)
        {
            SocketRole activeRole   = Utility.GetServer().GetRole(activeUserRole);
            SocketRole presentRole  = Utility.GetServer().GetRole(presentUserRole);
            SocketRole inactiveRole = Utility.GetServer().GetRole(inactiveUserRole);

            foreach (ulong id in userActivity.Keys)
            {
                UpdateUser(id, activeRole, presentRole, inactiveRole);
            }

            SerializationIO.SaveObjectToFile(Program.dataPath + activityFileName + Program.gitHubIgnoreType, userActivity);
            return(Task.CompletedTask);
        }
Example #20
0
        public static string AddGame(SocketUser user, string gameName)
        {
            string result = "";

            if (gameName != null && gameName != "")
            {
                gameName = gameName.ToUpper();

                bool doSave = false;
                if (userGames.ContainsKey(user.Id))
                {
                    if (!userGames[user.Id].Contains(gameName))
                    {
                        userGames[user.Id].Add(gameName);
                        Logging.Log(Logging.LogType.BOT, "Added game " + gameName + " to gamelist of " + user.Username);
                        result = "Succesfully added game **" + gameName + "** to your gamelist.";
                        doSave = true;
                    }
                    else
                    {
                        result = "Failed to add game **" + gameName + "** - It's already there.";
                    }
                }
                else
                {
                    userGames.Add(user.Id, new List <string> ());
                    userGames[user.Id].Add(gameName);
                    Logging.Log(Logging.LogType.BOT, "Constructed a new gamelist for " + user.Username);
                    result = "Succesfully added game **" + gameName + "** to your gamelist.";
                    doSave = true;
                }

                ChangeGameRole(user, gameName, true);

                if (doSave)
                {
                    SerializationIO.SaveObjectToFile(Program.dataPath + fileName + Program.gitHubIgnoreType, userGames);
                }
            }
            return(result);
        }
        public static void RecordActivity(ulong userID, DateTime time, bool single)
        {
            if (userActivity.ContainsKey(userID))
            {
                userActivity[userID] = time;
            }
            else
            {
                userActivity.Add(userID, time);
            }

            // Well that got ugly.
            SocketRole activeRole   = Utility.GetServer().GetRole(activeUserRole);
            SocketRole presentRole  = Utility.GetServer().GetRole(presentUserRole);
            SocketRole inactiveRole = Utility.GetServer().GetRole(inactiveUserRole);

            UpdateUser(userID, activeRole, presentRole, inactiveRole);

            if (single)
            {
                SerializationIO.SaveObjectToFile(Program.dataPath + activityFileName + Program.gitHubIgnoreType, userActivity);
            }
        }
Example #22
0
        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);
            };
        }
Example #23
0
        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);
                }
            };
        }
Example #24
0
 public void Save()
 {
     SerializationIO.SaveObjectToFile(Program.dataPath + "aliasses.dat", this);
 }
Example #25
0
 private static void Save()
 {
     SerializationIO.SaveObjectToFile(Program.dataPath + strikeDataPath + Program.gitHubIgnoreType, strikes);
 }
Example #26
0
 public static void SaveData()
 {
     SerializationIO.SaveObjectToFile(filePath, allPermissions, true, false);
 }
Example #27
0
 public static void SaveData()
 {
     SerializationIO.SaveObjectToFile(Program.dataPath + "quotes" + Program.gitHubIgnoreType, quotes, true, false);
 }
Example #28
0
 public static void SaveData()
 {
     SerializationIO.SaveObjectToFile(Program.dataPath + "younglings" + Program.gitHubIgnoreType, joinDate, true, false);
 }
Example #29
0
 public static void LoadData()
 {
     joinDate = SerializationIO.LoadObjectFromFile <Dictionary <ulong, Youngling> > (Program.dataPath + "younglings" + Program.gitHubIgnoreType);
 }
Example #30
0
 public static void SaveSettings()
 {
     SerializationIO.SaveObjectToFile(Program.dataPath + settingsFileName + Program.gitHubIgnoreType, settings, true, false);
 }