Esempio n. 1
0
        private async Task CheckReactions(RestUserMessage sm, RoleSelector rsm, bool dupchecker = false)
        {
            for (int i = 0; i < sm.Reactions.Count; i++)
            {
                var rd = sm.Reactions.ElementAt(i);

                var t = await sm.GetReactionUsersAsync(rd.Key, 100).FlattenAsync();

                if (!rd.Value.IsMe)
                {
                    foreach (var bb in t)
                    {
                        await sm.RemoveReactionAsync(rd.Key, bb);
                    }
                }
                else if (!dupchecker)
                {
                    var p = rsm.roles.Where(s => s.EmoteCheckCompare(rd.Key.Name)).ToList();
                    if (p.Count == 0)
                    {
                        foreach (var bb in t)
                        {
                            await sm.RemoveReactionAsync(rd.Key, bb);
                        }
                    }
                }
            }

            if (!dupchecker)
            {
                await GetEmotes(sm, rsm);
            }
        }
Esempio n. 2
0
        private async Task GetEmotes(RestUserMessage t, RoleSelector rsm)
        {
            int inc = -1;

            for (int i = 0; i < rsm.roles.Count; i++)
            {
                inc++;

                if (rsm.roles[inc].DefaultEmoji)
                {
                    Emoji e = new Emoji(rsm.roles[inc].Emote);

                    if (t.Reactions.Where(f => f.Key.Name == e.Name).ToList().Count == 0)
                    {
                        await t.AddReactionAsync(e);
                    }
                }
                else
                {
                    if (Emote.TryParse(rsm.roles[inc].Emote, out var emote))
                    {
                        if (t.Reactions.Where(f => f.Key.Name == emote.Name).ToList().Count == 0)
                        {
                            await t.AddReactionAsync(emote);
                        }
                    }
                }
            }
        }
Esempio n. 3
0
 private RoleSelector GetRoleSelector(GuildInfo thisGuildInfo, ulong id)
 {
     if (thisGuildInfo.rs.Where(d => d.messagechannel == id).ToList().Count > 0)
     {
         return(thisGuildInfo.rs.Where(d => d.messagechannel == id).ToList()[0]);
     }
     else
     {
         RoleSelector rsnew = new RoleSelector(0, id);
         thisGuildInfo.rs.Add(rsnew);
         return(rsnew);
     }
 }
Esempio n. 4
0
        private Role FindRole(SocketReaction message, RoleSelector rsm)
        {
            Role r = null;

            for (int i = 0; i < rsm.roles.Count; i++)
            {
                if (rsm.roles[i].NameFromEmojiString(message.Emote.Name) != "")
                {
                    r = rsm.roles[i];
                    break;
                }
            }
            return(r);
        }
Esempio n. 5
0
        private bool CheckVaildRoles(RoleSelector rsm, SocketUser author)
        {
            SocketGuildUser scgo = author as SocketGuildUser;

            for (int i = 0; i < rsm.ValidRolesIDs.Count; i++)
            {
                ulong br = rsm.ValidRolesIDs[i];

                if (scgo.Roles.Where(d => d.Id == br).ToList().Count > 0)
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 6
0
        private async Task DeleteOld(IChannel chano, RoleSelector rsm)
        {
            RestUserMessage sm = null;

            SocketTextChannel itso = chano as SocketTextChannel;

            ulong idd = rsm.storemessageid;

            if (idd > 0)
            {
                sm = await itso.GetMessageAsync(idd) as RestUserMessage;

                if (sm != null)
                {
                    await sm.DeleteAsync();
                }
            }
        }
Esempio n. 7
0
        private async Task TestGUI(SocketGuild guil)
        {
            GuildInfo bsu = null;

            if (botssaves.GGs.Where(d => d.guildid == guil.Id).ToList().Count == 0)
            {
                bsu = new GuildInfo(guil.Id);
                botssaves.GGs.Add(bsu);
            }
            else
            {
                bsu = botssaves.GGs.Where(d => d.guildid == guil.Id).ToList()[0];
            }

            for (int i = 0; i < bsu.rs.Count; i++)
            {
                RoleSelector rsm = bsu.rs[i];
                var          iso = guil.Channels.Where(c => c.Id == rsm.messagechannel).ToList();

                if (iso.Count > 0)
                {
                    SocketTextChannel itso = iso[0] as SocketTextChannel;

                    ulong idd = rsm.storemessageid;

                    if (idd == 0)
                    {
                        continue;
                    }

                    RestUserMessage sm = await itso.GetMessageAsync(idd) as RestUserMessage;

                    await LoadTheList(sm, rsm);
                }
            }

            Save();
        }
Esempio n. 8
0
        private EmbedBuilder MakeEmbed(RoleSelector rsm)
        {
            EmbedBuilder builder = new EmbedBuilder();

            builder.WithTitle(rsm.title);

            if (rsm.roles.Count == 0)
            {
                builder.WithDescription("Add Some Roles for Users to Pick From!");
            }
            else
            {
                builder.WithDescription(rsm.desc);
            }

            for (int i = 0; i < rsm.roles.Count; i++)
            {
                builder.AddField(rsm.roles[i].ValueName + " - @" + rsm.roles[i].RoleRealName, rsm.roles[i].Emote, false);
            }

            builder.WithColor(Color.Green);

            return(builder);
        }
Esempio n. 9
0
        private async Task CheckMessageTask(SocketMessage message)
        {
            SocketGuildUser sg = await(message.Channel as IChannel).GetUserAsync(message.Author.Id) as SocketGuildUser;

            IChannel chani = message.Channel;
            IGuild   guil  = sg.Guild;

            GuildInfo    thisGuildInfo = GetBSUFromID(guil.Id);
            RoleSelector rsMain        = GetRoleSelector(thisGuildInfo, chani.Id);

            ulong messageSelectorID = rsMain.storemessageid;

            ulong botOnlyID = thisGuildInfo.botonlychan.FirstOrDefault(x => x == chani.Id);

            string messages = message.Content;

            if (botOnlyID != 0 && messages.ToLower() != "delete bot only")
            {
                if (message.Attachments.Count > 0)
                {
                    for (int i = 0; i < message.Attachments.Count; i++)
                    {
                        await message.Channel.SendMessageAsync(message.Attachments.ElementAt(i).Url);
                    }
                }
                else
                {
                    await message.Channel.SendMessageAsync(messages);
                }

                await message.DeleteAsync();
            }

            if (!CheckVaildRoles(rsMain, message.Author))
            {
                if (guil.OwnerId != message.Author.Id)
                {
                    return;
                }
            }

            if (messages.ToLower() == "setup")
            {
                await message.DeleteAsync();

                await DeleteOld(chani, rsMain);

                EmbedBuilder builder = MakeEmbed(rsMain);

                RestUserMessage t = await message.Channel.SendMessageAsync("", false, builder.Build());

                await GetEmotes(t, rsMain);

                rsMain.storemessageid = t.Id;

                Save();
            }
            else if (messages.ToLower() == "make bot only")
            {
                await message.DeleteAsync();

                if (botOnlyID != 0)
                {
                    return;
                }

                thisGuildInfo.botonlychan.Add(chani.Id);

                Save();
            }
            else if (messages.ToLower() == "delete bot only")
            {
                await message.DeleteAsync();

                if (botOnlyID == 0)
                {
                    return;
                }

                thisGuildInfo.botonlychan.Remove(botOnlyID);

                Save();
            }
            else if (messages.ToLower() == "clearset")
            {
                await message.DeleteAsync();

                await DeleteOld(chani, rsMain);

                thisGuildInfo.rs.Remove(rsMain);

                Save();
            }
            else if (messages.Length > 11 && messages.ToLower().Substring(0, 11) == "deleteemote")
            {
                await message.DeleteAsync();

                string em = messages.Substring(12).Trim();

                Role deleter = null;
                for (int i = 0; i < rsMain.roles.Count; i++)
                {
                    if (rsMain.roles[i].NameFromEmojiString(em) != "")
                    {
                        deleter = rsMain.roles[i];
                        break;
                    }
                }

                rsMain.roles.Remove(deleter);

                Save();

                RestUserMessage sm = await message.Channel.GetMessageAsync(messageSelectorID) as RestUserMessage;

                await CheckReactions(sm, rsMain);

                await sm.ModifyAsync(msg => msg.Embed = MakeEmbed(rsMain).Build());
            }
            else if (messages.Length > 10 && messages.ToLower().Substring(0, 10) == "deleterole")
            {
                await message.DeleteAsync();

                string em = messages.Substring(11).Trim();

                Role deleter = null;
                for (int i = 0; i < rsMain.roles.Count; i++)
                {
                    if (rsMain.roles[i].NameFromEmojiString(em) != "")
                    {
                        deleter = rsMain.roles[i];
                        break;
                    }
                }

                lastdead = deleter;

                rsMain.roles.Remove(deleter);

                Save();

                RestUserMessage sm = await message.Channel.GetMessageAsync(messageSelectorID) as RestUserMessage;

                await CheckReactions(sm, rsMain);

                await sm.ModifyAsync(msg => msg.Embed = MakeEmbed(rsMain).Build());
            }
            else if (messages.Length > 8 && messages.ToLower().Substring(0, 8) == "editrole")
            {
                await message.DeleteAsync();

                string em = messages.Substring(9).Trim();

                IRole role = null;
                if (em.IndexOf("<") >= 0)
                {
                    string drrule = em.Substring(3);
                    drrule = drrule.Substring(0, drrule.IndexOf(">"));

                    role = guil.GetRole(Convert.ToUInt64(drrule));

                    if (role == null)
                    {
                        return;
                    }

                    if (rsMain.roles.Where(x => x.roleID == Convert.ToUInt64(drrule)).ToList().Count == 0)
                    {
                        return;
                    }

                    Role eee = rsMain.roles.Where(x => x.roleID == Convert.ToUInt64(drrule)).ToList()[0];

                    string[] ss2 = em.Split(' ');

                    ss2[0] = "";
                    string newName = string.Join(" ", ss2).Trim();

                    if (newName == "")
                    {
                        return;
                    }

                    eee.ValueName = newName;
                }

                Save();

                RestUserMessage sm = await message.Channel.GetMessageAsync(messageSelectorID) as RestUserMessage;

                await CheckReactions(sm, rsMain);

                await sm.ModifyAsync(msg => msg.Embed = MakeEmbed(rsMain).Build());
            }
            else if (messages.Length > 8 && messages.ToLower().Substring(0, 8) == "addemote")
            {
                await message.DeleteAsync();

                string m2 = messages.Substring(9);

                string[] ss = m2.Split(' ');

                string em = ss[0];
                ss[0] = "";
                string rulename = string.Join(" ", ss).Trim();

                if (rulename.Length <= 0)
                {
                    return;
                }

                if (em.Length >= 4)
                {
                    Emote e = null;
                    if (Emote.TryParse(em, out var emote))
                    {
                        e = emote;
                    }

                    if (e == null)
                    {
                        return;
                    }
                    else if (guil.Emotes.Where(x => x.Id == e.Id).ToList().Count == 0)
                    {
                        return;
                    }
                }

                IRole role = null;
                if (rulename.IndexOf("<") >= 0)
                {
                    string drrule = rulename.Substring(3);
                    drrule = drrule.Substring(0, drrule.IndexOf(">"));

                    role = guil.GetRole(Convert.ToUInt64(drrule));

                    string[] ss2 = rulename.Split(' ');

                    ss2[0] = "";
                    string newName = string.Join(" ", ss2).Trim();

                    rulename = newName == "" ? role.Name : newName;
                }

                Role rboi = new Role(rulename, em, em.Length == 2);

                if (role == null)
                {
                    role = guil.Roles.FirstOrDefault(x => x.Name == rulename);
                }

                if (role == null)
                {
                    role = await guil.CreateRoleAsync(rulename, null, null, false, null);
                }

                rboi.roleID       = role.Id;
                rboi.RoleRealName = role.Name;

                rsMain.roles.Add(rboi);

                Save();

                RestUserMessage sm = await message.Channel.GetMessageAsync(messageSelectorID) as RestUserMessage;

                await sm.ModifyAsync(msg => msg.Embed = MakeEmbed(rsMain).Build());
                await GetEmotes(sm, rsMain);
            }
            else if (messages.Length > 8 && messages.ToLower().Substring(0, 8) == "addvalid")
            {
                await message.DeleteAsync();

                string rle = messages.Substring(9).Trim();

                if (rle.IndexOf("<") == -1 || rle.IndexOf(">") == -1)
                {
                    return;
                }

                rle = rle.Substring(3);
                rle = rle.Substring(0, rle.IndexOf(">"));

                IRole irsf = CheckIfRole(rle, guil);

                if (irsf == null)
                {
                    return;
                }

                rsMain.ValidRolesIDs.Add(irsf.Id);

                Save();
            }
            else if (messages.Length > 11 && messages.ToLower().Substring(0, 11) == "removevalid")
            {
                await message.DeleteAsync();

                string rle = messages.Substring(12).Trim();

                if (rle.IndexOf("<") == -1 || rle.IndexOf(">") == -1)
                {
                    return;
                }

                rle = rle.Substring(3);
                rle = rle.Substring(0, rle.IndexOf(">"));

                IRole irsf = CheckIfRole(rle, guil);

                if (irsf == null)
                {
                    return;
                }

                rsMain.ValidRolesIDs.Add(irsf.Id);

                Save();
            }
            else if (messages.Length > 9 && messages.ToLower().Substring(0, 9) == "edittitle")
            {
                await message.DeleteAsync();

                string rle = messages.Substring(10).Trim();

                if (rle == "")
                {
                    return;
                }

                rsMain.title = rle;

                Save();

                RestUserMessage sm = await message.Channel.GetMessageAsync(messageSelectorID) as RestUserMessage;

                await sm.ModifyAsync(msg => msg.Embed = MakeEmbed(rsMain).Build());
            }
            else if (messages.Length > 8 && messages.ToLower().Substring(0, 8) == "editdesc")
            {
                await message.DeleteAsync();

                string rle = messages.Substring(9).Trim();

                if (rle == "")
                {
                    return;
                }

                rsMain.desc = rle;

                Save();

                RestUserMessage sm = await message.Channel.GetMessageAsync(messageSelectorID) as RestUserMessage;

                await sm.ModifyAsync(msg => msg.Embed = MakeEmbed(rsMain).Build());
            }
        }
Esempio n. 10
0
        private async Task RoleChanges(SocketReaction message, bool add)
        {
            var      user = message.User.Value as SocketGuildUser;
            IGuild   gg   = (user as IGuildUser).Guild;
            IChannel chai = message.Channel;

            GuildInfo    bsu    = GetBSUFromID(gg.Id);
            RoleSelector rsMain = GetRoleSelector(bsu, chai.Id);

            ulong messageSelectorID = rsMain.storemessageid;

            if (message.MessageId != messageSelectorID)
            {
                return;
            }

            if (add)
            {
                if (message.User.Value.IsBot)
                {
                    return;
                }

                RestUserMessage sm = await message.Channel.GetMessageAsync(messageSelectorID) as RestUserMessage;
                await CheckReactions(sm, rsMain, true);

                Role r = FindRole(message, rsMain);

                if (r != null)
                {
                    var role = gg.GetRole(r.roleID);

                    if (role == null)
                    {
                        role = gg.Roles.FirstOrDefault(x => x.Name == r.ValueName);
                    }

                    if (role == null)
                    {
                        role = await gg.CreateRoleAsync(r.ValueName, null, null, false, null);
                    }

                    if (!user.Roles.Contains(role))
                    {
                        await user.AddRoleAsync(role);
                    }
                }
            }
            else
            {
                if (message.User.Value.IsBot)
                {
                    if (lastdead == null || !lastdead.EmoteCheckCompare(message.Emote.Name))
                    {
                        return;
                    }

                    var role = gg.GetRole(lastdead.roleID);

                    if (role == null)
                    {
                        role = gg.Roles.FirstOrDefault(x => x.Name == lastdead.ValueName);
                    }

                    if (role == null)
                    {
                        return;
                    }

                    for (int i = 0; i < gg.Roles.Count; i++)
                    {
                        var arbor = gg.Roles.ElementAt(i);

                        if (arbor == role)
                        {
                            await arbor.DeleteAsync();
                        }
                    }

                    lastdead = null;
                }

                Role r = FindRole(message, rsMain);

                if (r != null)
                {
                    var role = gg.GetRole(r.roleID);

                    if (role == null)
                    {
                        role = gg.Roles.FirstOrDefault(x => x.Name == r.ValueName);
                    }

                    if (role == null)
                    {
                        role = await gg.CreateRoleAsync(r.ValueName, null, null, false, null);
                    }

                    if (user.Roles.Contains(role))
                    {
                        await user.RemoveRoleAsync(role);
                    }
                }
            }
        }
Esempio n. 11
0
        private async Task LoadTheList(RestUserMessage sm, RoleSelector rsm)
        {
            await sm.ModifyAsync(msg => msg.Embed = MakeEmbed(rsm).Build());

            await CheckReactions(sm, rsm);
        }