Ejemplo n.º 1
0
        public async Task Announce(CommandContext ctx, string gameName, string streamName, string link, int?time = null)
        {
            if (time == null)
            {
                await BotInitSettings.GetAnnountmentsChannel(ctx.Guild)
                .SendMessageAsync(BotInitSettings.GetStreamSubscriberRole(ctx.Guild).Mention + " " +
                                  ctx.Member.Mention + " стримт " + gameName + " [" + streamName + "] " + link).ThrowTaskException();

                await ctx.Message.DeleteAsync();

                //don't write anything after it
            }
            else
            {
                var msg = await BotInitSettings.GetAnnountmentsChannel(ctx.Guild)
                          .SendMessageAsync(BotInitSettings.GetStreamSubscriberRole(ctx.Guild).Mention + " " +
                                            ctx.Member.Mention + " будует стримить " + gameName + " [" + streamName + "] через " + time.Value.ToString() + " мин.")
                          .ThrowTaskException();

                var emoji = DiscordEmoji.FromName(ctx.Client, ":eyes:");
                await msg.CreateReactionAsync(emoji).ThrowTaskException();

                await ctx.Message.DeleteAsync();

                await Task.Delay(time.Value * 60 * 1000);

                await Announce(ctx, gameName, streamName, link);
            }
        }
Ejemplo n.º 2
0
        public static void CensorChat(DiscordMessage msg, DiscordGuild guild, DiscordClient client)
        {
            var censorWords = File.ReadAllText(".\\CensorWords.txt").Split("\r\n");

            if (BotInitSettings.ServersData.ContainsKey(guild.Id) &&        /*init check*/
                msg.Channel != BotInitSettings.GetUncensorChannel(guild) &&
                msg.Author != client.CurrentUser)
            {
                var content = msg.Content.ToLower();

                if (content.Split(' ', '-', '_', '&', '(', ')', '!').ContainsAnyElementOf(censorWords))
                {
                    msg.DeleteAsync();

                    var member = guild.GetMemberAsync(msg.Author.Id).Result;

                    msg.Channel
                    .SendMessageAsync(member.Mention + " ваше сообщение было удалено по причине ислользования нецензурной лексики.\r\n Вы были заглушены на 02:00:00");

                    member.RevokeRoleAsync(BotInitSettings.GetDefaultMemberRole(guild));
                    member.GrantRoleAsync(BotInitSettings.GetMutedMemberRole(guild));

                    Task.Run(async() =>
                    {
                        var span = new TimeSpan(2, 0, 0);
                        await Task.Delay((int)span.TotalMilliseconds);

                        await member.GrantRoleAsync(BotInitSettings.GetDefaultMemberRole(guild)).ThrowTaskException();
                        await member.RevokeRoleAsync(BotInitSettings.GetMutedMemberRole(guild)).ThrowTaskException();

                        await msg.Channel.SendMessageAsync(member.Mention + " теперь может говорить(и писать тоже)!");
                    });
                }
            }
        }
Ejemplo n.º 3
0
        public async Task MuteMember(CommandContext ctx, DiscordMember member, string reason, string time)
        {
            if (ctx.Member.PermissionsIn(ctx.Channel).HasPermission(Permissions.KickMembers) == false)
            {
                var msg = await ctx.Channel.SendMessageAsync("У вас недостаточно прав для этого");

                await Task.Delay(3000);

                await msg.DeleteAsync();

                return;
            }

            time = time == "-1" ? null : time;

            await member.RevokeRoleAsync(BotInitSettings.GetDefaultMemberRole(ctx.Guild)).ThrowTaskException();

            await member.GrantRoleAsync(BotInitSettings.GetMutedMemberRole(ctx.Guild)).ThrowTaskException();

            await ctx.Message.DeleteAsync();

            await ctx.Channel.SendMessageAsync(member.Mention + " заглушон на " + (time?.ToString() ?? "неограниченное время") + " по причине " + (reason ?? "*НЕЗАДАНО*"));

            if (time == null)
            {
                return;
            }
            else
            {
                var span = TimeSpan.Parse(time);
                await Task.Delay((int)span.TotalMilliseconds);

                await UnmuteMember(ctx, member).ThrowTaskException();
            }
        }
Ejemplo n.º 4
0
        public async Task UnsubscribeFromStreams(CommandContext ctx)
        {
            await ctx.Member.RevokeRoleAsync(BotInitSettings.GetStreamSubscriberRole(ctx.Guild));

            var msg = await ctx.Channel.SendMessageAsync(ctx.Member.Mention + " отподписался от стримов");

            await ctx.Message.DeleteAsync();

            await Task.Delay(3000);

            await msg.DeleteAsync();
        }
Ejemplo n.º 5
0
        public async Task SubscribeToStreams(CommandContext ctx)
        {
            await ctx.Member.GrantRoleAsync(BotInitSettings.GetStreamSubscriberRole(ctx.Guild));

            var msg = await ctx.Channel.SendMessageAsync(ctx.Member.Mention + " подписался на стримы");

            await ctx.Message.DeleteAsync();

            await Task.Delay(3000);

            await msg.DeleteAsync();
        }
Ejemplo n.º 6
0
        public async Task UnmuteMember(CommandContext ctx, DiscordMember member)
        {
            if (ctx.Member.PermissionsIn(ctx.Channel).HasPermission(Permissions.KickMembers) == false)
            {
                var msg = await ctx.Channel.SendMessageAsync("У вас недостаточно прав для этого");

                await Task.Delay(3000);

                await msg.DeleteAsync();

                return;
            }

            await member.GrantRoleAsync(BotInitSettings.GetDefaultMemberRole(ctx.Guild)).ThrowTaskException();

            await member.RevokeRoleAsync(BotInitSettings.GetMutedMemberRole(ctx.Guild)).ThrowTaskException();

            await ctx.Channel.SendMessageAsync(member.Mention + " теперь может говорить(и писать тоже)!");

            await ctx.Message.DeleteAsync();
        }
Ejemplo n.º 7
0
        public async Task CreateChanel(CommandContext ctx, string name)
        {
            var overwrites = new DiscordOverwriteBuilder[] { new DiscordOverwriteBuilder()
                                                             {
                                                                 Allowed = Permissions.All
                                                             }.For(ctx.Member) };
            var channel = await ctx.Guild.CreateChannelAsync(name, ChannelType.Voice, overwrites : overwrites,
                                                             parent : BotInitSettings.GetVoiceChannelCategory(ctx.Guild)).ThrowTaskException();

            await ctx.Message.DeleteAsync();

            var msg = await ctx.Channel.SendMessageAsync("Канал " + name + " создан!").ThrowTaskException();

            await Task.Delay(10000);

            await msg.DeleteAsync();

            while (channel.Users.Any())
            {
                Thread.Sleep(1);
            }

            await channel.DeleteAsync();
        }
Ejemplo n.º 8
0
        public async Task CreateTeamGame(CommandContext ctx, string gameName, int targetMemberCount, string description)
        {
            var channel = BotInitSettings.GetTeamFindingChannel(ctx.Guild);

            var msg = await channel.SendMessageAsync(ctx.Member.Mention + " ищет напарника(ов) для игры в " +
                                                     gameName + "\n" + "Доп. иформация: " + description +
                                                     (targetMemberCount == -1 ? "" : ("\n\n" + "Для игры нужно " + targetMemberCount + " человек(а)")));

            await msg.CreateReactionAsync(DiscordEmoji.FromName(ctx.Client, ":ok_hand:"));

            if (targetMemberCount == -1)
            {
                await msg.CreateReactionAsync(DiscordEmoji.FromName(ctx.Client, ":arrow_forward:"));
            }

            await ctx.Message.DeleteAsync();

            var interact = ctx.Client.GetInteractivity();
            var dm       = await ctx.Member.CreateDmChannelAsync();

            List <DiscordUser> userList;

            if (targetMemberCount != -1)
            {
                while (true)
                {
                    Func <MessageReactionAddEventArgs, bool> predecate = (s) => s.Message == msg && s.Emoji == DiscordEmoji.FromName(ctx.Client, ":ok_hand:");
                    await interact.WaitForReactionAsync(predecate);

                    var users = await msg.GetReactionsAsync(DiscordEmoji.FromName(ctx.Client, ":ok_hand:"));

                    if (users.Count - 1 >= targetMemberCount)
                    {
                        userList = users.Where((s, i) => 0 <= i && i <= targetMemberCount - 1).ToList();                         //Bot reaction ignore

                        await dm.SendMessageAsync("Ваша игра готова к старту! Зайдите в канал и одобрите старт!");

                        await msg.CreateReactionAsync(DiscordEmoji.FromName(ctx.Client, ":arrow_forward:"));

                        var retry = true;
                        while (retry)
                        {
                            retry = (await interact.WaitForReactionAsync
                                         (s => s.Message == msg && s.User == ctx.User && s.Emoji == DiscordEmoji.FromName(ctx.Client, ":arrow_forward:"))).TimedOut;
                        }

                        break;
                    }
                }
            }
            else
            {
                Func <MessageReactionAddEventArgs, bool> predecate = (s) => s.Message == msg && s.Emoji == DiscordEmoji.FromName(ctx.Client, ":arrow_forward:");

                var retry = true;
                while (retry)
                {
                    retry = (await interact.WaitForReactionAsync
                                 (s => s.Message == msg && s.Emoji == DiscordEmoji.FromName(ctx.Client, ":arrow_forward:"), new TimeSpan(0, 10, 0))).TimedOut;

                    await dm.SendMessageAsync("Незабывайте про созданую игру. Возможно уже пора начинать!");
                }

                var users = await msg.GetReactionsAsync(DiscordEmoji.FromName(ctx.Client, ":ok_hand:"));

                userList = users.Where((s, i) => 0 <= i && i <= targetMemberCount - 1).ToList();                 //Bot reaction ignore
            }

            var msg2 = await
                       channel.SendMessageAsync("Игра в " + gameName + " запущена!" + "\n\n" + "Участники: " + string.Join(", ", userList.Select(s => s.Mention)));

            var name = "Играем в " + gameName;

            var overwrites = new DiscordOverwriteBuilder[] { new DiscordOverwriteBuilder()
                                                             {
                                                                 Allowed = Permissions.All
                                                             }.For(ctx.Member) };
            var voiceChannel = await ctx.Guild.CreateChannelAsync(name, ChannelType.Voice, overwrites : overwrites,
                                                                  parent : BotInitSettings.GetVoiceChannelCategory(ctx.Guild)).ThrowTaskException();

            var deleteTask = Task.Run(() =>
            {
                Thread.Sleep(10000);

                while (voiceChannel.Users.Any())
                {
                    Thread.Sleep(1);
                }
                voiceChannel.DeleteAsync();
            });

            await Task.Delay(3000);

            await msg.DeleteAsync();

            await Task.Delay(120000);

            await msg2.DeleteAsync();

            await deleteTask;
        }
Ejemplo n.º 9
0
        public async Task HelloNewMember(CommandContext ctx)
        {
            await ctx.Member.GrantRoleAsync(BotInitSettings.GetDefaultMemberRole(ctx.Guild)).ThrowTaskException();

            await ctx.Message.DeleteAsync().ThrowTaskException();
        }