Beispiel #1
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);
                };
            }
        }
Beispiel #2
0
        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);
                }
            }
        }
Beispiel #3
0
            public Task <Result> Execute(SocketUserMessage e, DateTime parse)
            {
                Birthdays.SetBirthday(e.Author.Id, parse);
                CultureInfo info = new CultureInfo(UserConfiguration.GetSetting <string> (e.Author.Id, "Culture"));

                return(TaskResult(null, "You have succesfully set your birthday to **" + parse.ToString(info) + "**."));
            }
Beispiel #4
0
 public static void ChangeGameRole(SocketUser user, string gameName, bool add)
 {
     // When you need to use containskey, but want it to ignore case /shrug
     if (gameRoles.Where(x => x.Key.ToUpper() == gameName).Count() != 0 && UserConfiguration.GetSetting <bool> (user.Id, "AutoManageGameRoles"))
     {
         ulong      roleID = gameRoles [gameName];
         SocketRole role   = Utility.GetServer().GetRole(roleID);
         if (role != null)
         {
             if (add)
             {
                 Utility.SecureAddRole(user as SocketGuildUser, role);
             }
             else
             {
                 Utility.SecureRemoveRole(user as SocketGuildUser, role);
             }
         }
         else
         {
             Logging.Log(Logging.LogType.WARNING, "Failed to find game role for " + gameName + " despite the data being present, please make sure the ID's match up as well.");
         }
     }
 }
        public static async Task UpdateVoiceChannel(SocketVoiceChannel voice)
        {
            Game highestGame = new Game("", "", StreamType.NotStreaming);

            if (voice != null && allVoiceChannels.ContainsKey(voice.Id))
            {
                VoiceChannel           voiceChannel = allVoiceChannels [voice.Id];
                List <SocketGuildUser> users        = Utility.ForceGetUsers(voice.Id);

                if (voiceChannel.ignore)
                {
                    return;
                }

                if (voice.Users.Count() == 0)
                {
                    voiceChannel.Reset();
                }
                else
                {
                    if (voiceChannel.desiredMembers > 0)
                    {
                        if (users.Count >= voiceChannel.desiredMembers)
                        {
                            voiceChannel.SetStatus(VoiceChannel.VoiceChannelStatus.Full, false);
                        }
                        else
                        {
                            voiceChannel.SetStatus(VoiceChannel.VoiceChannelStatus.Looking, false);
                        }
                    }
                }

                Dictionary <Game, int> numPlayers = new Dictionary <Game, int> ();
                foreach (SocketGuildUser user in users)
                {
                    if (UserConfiguration.GetSetting <bool> (user.Id, "AutoLooking") && users.Count == 1)
                    {
                        voiceChannel.SetStatus(VoiceChannel.VoiceChannelStatus.Looking, false);
                    }

                    if (user.Game.HasValue && user.IsBot == false)
                    {
                        if (numPlayers.ContainsKey(user.Game.Value))
                        {
                            numPlayers [user.Game.Value]++;
                        }
                        else
                        {
                            numPlayers.Add(user.Game.Value, 1);
                        }
                    }
                }

                int highest = int.MinValue;

                for (int i = 0; i < numPlayers.Count; i++)
                {
                    KeyValuePair <Game, int> value = numPlayers.ElementAt(i);

                    if (value.Value > highest)
                    {
                        highest     = value.Value;
                        highestGame = value.Key;
                    }
                }

                if (enableVoiceChannelTags)
                {
                    GetTags(voiceChannel);
                }

                string tagsString = "";
                foreach (VoiceChannelTag tag in voiceChannel.currentTags)
                {
                    tagsString += tag.tagEmoji;
                }
                tagsString += tagsString.Length > 0 ? " " : "";

                string [] splitVoice      = voiceChannel.name.Split(';');
                string    possibleShorten = shortenChannelNames && splitVoice.Length > 1 ? splitVoice [1] : splitVoice [0];
                int       mixedLimit      = highest >= 2 ? 2 : Utility.ForceGetUsers(voice.Id).Count == 1 ? int.MaxValue : 1;                                                                                                         // Nested compact if statements? What could go wrong!

                string gameName = numPlayers.Where(x => x.Value >= mixedLimit).Count() > mixedLimit ? "Mixed Games" : gameNameReplacements.ContainsKey(highestGame.Name) ? gameNameReplacements[highestGame.Name] : highestGame.Name; // What even is this

                string newName;
                if (autoRenameChannels)
                {
                    newName = gameName != "" ? tagsString + possibleShorten + " - " + gameName : tagsString + splitVoice [0];
                }
                else
                {
                    newName = tagsString + splitVoice [0];
                }

                if (voiceChannel.customName != "")
                {
                    newName = tagsString + possibleShorten + " - " + voiceChannel.customName;
                }

                // Trying to optimize API calls here, just to spare those poor souls at the Discord API HQ stuff
                if (voice.Name != newName)
                {
                    Logging.Log(Logging.LogType.BOT, "Channel name updated: " + newName);
                    await voice.ModifyAsync((delegate(VoiceChannelProperties properties) {
                        properties.Name = newName;
                    }));
                }
                voiceChannel.CheckLocker();
            }
        }
Beispiel #6
0
 /// <summary>
 /// Formatted for the danish format!
 /// </summary>
 public static bool TryParseDatetime(string input, ulong userID, out DateTime result) {
     CultureInfo danishCulture = new CultureInfo (UserConfiguration.GetSetting<string>(userID, "Culture"));
     return DateTime.TryParse (input, danishCulture.DateTimeFormat, DateTimeStyles.None, out result);
 }
Beispiel #7
0
        public static async Task <FoundCommandResult> FindAndExecuteCommand(SocketMessage e, string commandName, List <string> arguements, Command [] commandList, int depth, bool printMessage, bool allowQuickCommands)
        {
            for (int i = 0; i < commandList.Length; i++)
            {
                if (commandList [i].command == commandName)
                {
                    if (arguements.Count > 0 && arguements [0] == "?")
                    {
                        Command command = commandList [i];
                        if (command is CommandSet)
                        {
                            messageControl.SendMessage(e, command.GetHelp(e), command.allowInMain);
                        }
                        else
                        {
                            messageControl.SendEmbed(e.Channel, command.GetHelpEmbed(e, UserConfiguration.GetSetting <bool> (e.Author.Id, "AdvancedCommandsMode")));
                        }
                        return(null);
                    }
                    else
                    {
                        FoundCommandResult result = new FoundCommandResult(await commandList [i].TryExecute(e as SocketUserMessage, depth, arguements.ToArray()), commandList [i]);
                        if (result != null)
                        {
                            if (printMessage)
                            {
                                messageControl.SendMessage(e, result.result.message, result.command.allowInMain);
                            }

                            if (depth == 0)
                            {
                                CommandVariables.Clear(e.Id);
                            }

                            return(result);
                        }
                    }
                }
            }

            if (allowQuickCommands)
            {
                return(await FindAndExecuteCommand(e, commandName, arguements, quickCommands.ToArray(), depth, printMessage, false));
            }

            return(null);
        }