Example #1
0
        public void GenerateConfig()
        {
            _json               = new JObject();
            guildName           = guild.Name;
            guildId             = guild.Id;
            prefix              = "$";
            sendLeaveMessage    = true;
            sendWelcomeMessage  = true;
            defaultRole         = 0;
            giveDefaultRole     = false;
            welcomeMessage      = "uh oh, $(user.Name) just joined";
            leaveMessage        = "$(user.Name) just left, big sad";
            permissions         = new PermissionsHandler();
            userlevels          = new Dictionary <ulong, Levels>();
            rolesPerLevel       = new Dictionary <int, IRole>();
            showLevelUpMessage  = true;
            useLevels           = true;
            voiceChannelTimeOut = 60;
            foreach (var user in guild.GetUsersAsync().GetAwaiter().GetResult())
            {
                userlevels.Add(user.Id, new Levels());
            }
            try
            {
                welcomeLeaveChannel = guild.GetDefaultChannelAsync().Result.Id;
            }
            catch (Exception)
            {
                welcomeLeaveChannel = 0;
            }
            try
            {
                musicChannel = guild.GetDefaultChannelAsync().Result.Id;
            }
            catch (Exception)
            {
                musicChannel = 0;
            }
            loop  = 0;
            queue = new Music.Queue();

            SaveConfig();
        }
Example #2
0
 public GuildHandle(IGuild guild)
 {
     this.guild   = guild;
     database     = new Database(guild);
     musicHandle  = new MusicHandler(guild, database);
     levelHandler = new LevelHandler(OnUserLevelUp, database);
     //permissionsHandler = new PermissionsHandler();
     if (database.queue != null)
     {
         musicHandle.queue = database.queue;
     }
     foreach (var channel in guild.GetChannelsAsync().GetAwaiter().GetResult())
     {
         channelHelps.Add(channel.Id, null);
     }
     permissionsHandler = database.permissions;
     permissionsHandler.SetPerms(guild.OwnerId, new Permissions()
     {
         perms = new string[] { "Commands.Music", "Commands.User", "Commands.GuildOwner", "Commands.Guild" }
     });
     helpEmbeds = BuildEmbed(database.prefix);
     Task.Run(GuildThread);
     //levelHandler.levelup += OnUserLevelUp();
 }
Example #3
0
 public void ParseConfig()
 {
     if (_json.ContainsKey("guildName"))
     {
         guildName = (string)_json["guildName"];
     }
     if (_json.ContainsKey("guildId"))
     {
         guildId = (ulong)_json["guildId"];
     }
     if (_json.ContainsKey("prefix"))
     {
         prefix = (string)_json["prefix"];
     }
     if (_json.ContainsKey("sendLeaveMessage"))
     {
         sendLeaveMessage = (bool)_json["sendLeaveMessage"];
     }
     if (_json.ContainsKey("sendWelcomeMessage"))
     {
         sendWelcomeMessage = (bool)_json["sendWelcomeMessage"];
     }
     if (_json.ContainsKey("welcomeMessage"))
     {
         welcomeMessage = (string)_json["welcomeMessage"];
     }
     if (_json.ContainsKey("leaveMessage"))
     {
         leaveMessage = (string)_json["leaveMessage"];
     }
     if (_json.ContainsKey("welcomeLeaveChannel"))
     {
         welcomeLeaveChannel = (ulong)_json["welcomeLeaveChannel"];
     }
     if (_json.ContainsKey("musicChannel"))
     {
         musicChannel = (ulong)_json["musicChannel"];
     }
     if (_json.ContainsKey("giveDefaultRole"))
     {
         giveDefaultRole = (bool)_json["giveDefaultRole"];
     }
     if (_json.ContainsKey("useLevels"))
     {
         useLevels = (bool)_json["useLevels"];
     }
     if (_json.ContainsKey("showLevelUpMessage"))
     {
         showLevelUpMessage = (bool)_json["showLevelUpMessage"];
     }
     if (_json.ContainsKey("voiceChannelTimeOut"))
     {
         voiceChannelTimeOut = (int)_json["voiceChannelTimeOut"];
     }
     if (_json.ContainsKey("defaultRole"))
     {
         if (guild.Roles.Any(n => n.Id == (ulong)_json["defaultRole"]))
         {
             defaultRole = (ulong)_json["defaultRole"];
         }
         else
         {
             giveDefaultRole = false;
         }
     }
     if (_json.ContainsKey("loop"))
     {
         loop = (LoopType)(int)_json["loop"];
     }
     if (_json.ContainsKey("queue"))
     {
         queue = new Music.Queue();
         foreach (var song in _json.Properties().Where(n => n.Name == "queue").First().Values())
         {
             var so = new Music.ISong();
             so.fileName = (string)song;
             if (so.FileExists())
             {
                 queue.Enqueue(so);
             }
         }
     }
     permissions = new PermissionsHandler();
     if (_json.ContainsKey("permissions"))
     {
         try
         {
             foreach (var perm in _json["permissions"].Children <JProperty>())
             {
                 ulong.TryParse(perm.Name, out ulong id);
                 if (!permissions.userPerms.ContainsKey(id))
                 {
                     permissions.userPerms.Add(id, new Permissions()
                     {
                         perms = new string[] { "" }
                     });
                     List <string> permstoadd = new List <string>(new string[] { "" });
                     if (perm.HasValues)
                     {
                         foreach (var pee in perm.Values())
                         {
                             permstoadd.Add((string)pee);
                         }
                     }
                     permissions.userPerms[id].perms = permstoadd.ToArray();
                 }
             }
         }
         catch (Exception e)
         {
             Logger.Error("Could not load old permissions for guild " + guild.Name + " (" + guild.Id + ")" + e);
         }
     }
     if (_json.ContainsKey("rolepermissions"))
     {
         try
         {
             foreach (var roleperm in _json["rolepermissions"].Children <JProperty>())
             {
                 ulong.TryParse(roleperm.Name, out ulong roleid);
                 if (!permissions.rolePerms.ContainsKey(roleid))
                 {
                     permissions.rolePerms.Add(roleid, new Permissions()
                     {
                         perms = new string[] { "" }
                     });
                     List <string> rolestoadd = new List <string>(new string[] { "" });
                     if (roleperm.HasValues)
                     {
                         foreach (var rolepee in roleperm.Values())
                         {
                             rolestoadd.Add((string)rolepee);
                         }
                     }
                     permissions.rolePerms[roleid].perms = rolestoadd.ToArray();
                 }
             }
         } catch (Exception e)
         {
             Logger.Error("Could not load old role permissions for guild " + guild.Name + " (" + guild.Id + ")" + e);
         }
     }
     userlevels = new Dictionary <ulong, Levels>();
     foreach (var user in guild.GetUsersAsync().GetAwaiter().GetResult())
     {
         userlevels.Add(user.Id, new Levels());
     }
     if (_json.ContainsKey("userLevels"))
     {
         try
         {
             foreach (var userlevel in _json["userLevels"].Children <JProperty>())
             {
                 ulong.TryParse(userlevel.Name, out ulong userid);
                 if (!userlevels.ContainsKey(userid))
                 {
                     userlevels.Add(userid, new Levels()
                     {
                         level = (int)userlevel.Value["level"], messagesSentSinceLevelUp = (int)userlevel.Value["messagesSentSinceLevelUp"], totalMessageSent = (int)userlevel.Value["totalMessagesSent"]
                     });
                 }
                 else
                 {
                     userlevels[userid].level = (int)userlevel.Value["level"];
                     userlevels[userid].messagesSentSinceLevelUp = (int)userlevel.Value["messagesSentSinceLevelUp"];
                     userlevels[userid].totalMessageSent         = (int)userlevel.Value["totalMessagesSent"];
                 }
             }
         } catch (Exception e)
         {
             Logger.Error($"Could not load old userLevels for guild {guild.Name} ({guild.Id})" + e);
         }
     }
     rolesPerLevel = new Dictionary <int, IRole>();
     if (_json.ContainsKey("roleLevels"))
     {
         try
         {
             var roleids = guild.Roles;
             foreach (var rolelevel in _json["roleLevels"].Children <JProperty>())
             {
                 ulong.TryParse(rolelevel.Name, out ulong roleid);
                 int key = (int)rolelevel.Values().First();
                 if (roleids.Select(n => n.Id).Any(n => n.Equals(roleid)))
                 {
                     rolesPerLevel.Add(key, roleids.First(n => n.Id == roleid));
                 }
             }
         } catch (Exception e)
         {
             Logger.Error($"Could not load old roleLevels for guild {guild.Name} ({guild.Id})", e);
         }
     }
 }