コード例 #1
0
ファイル: Join.cs プロジェクト: maxderegt/TotallyNotABot
        public async Task <VoiceNextConnection> RunCommand(CommandContext ctx, Player player, VoiceNextConnection connection, VoiceNextClient voice)
        {
            if (connection != null)
            {
                return(connection);
            }
            try
            {
                player.Stop();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            DiscordChannel channel = ctx.Member.VoiceState.Channel;

            if (channel == null)
            {
                await ctx.RespondAsync("You need to be in a voice channel.");
            }
            else
            {
                connection = await voice.ConnectAsync(channel);

                Console.WriteLine("connection established");
            }

            return(connection);
        }
コード例 #2
0
        public async Task Join(CommandContext ctx, DiscordChannel chn = null)
        {
            // check whether VNext is enabled
            VoiceNextClient vnext = ctx.Client.GetVoiceNextClient();

            if (vnext == null)
            {
                // not enabled
                await ctx.RespondAsync("VNext is not enabled or configured.");

                return;
            }

            // check whether we aren't already connected
            VoiceNextConnection vnc = vnext.GetConnection(ctx.Guild);

            if (vnc != null)
            {
                // already connected
                await ctx.RespondAsync("Already connected in this guild.");

                return;
            }

            // get member's voice state
            var vstat = ctx.Member?.VoiceState;

            if (vstat?.Channel == null && chn == null)
            {
                // they did not specify a channel and are not in one
                await ctx.RespondAsync("You are not in a voice channel.");

                return;
            }

            // channel not specified, use user's
            if (chn == null)
            {
                chn = vstat.Channel;
            }

            // connect
            vnc = await vnext.ConnectAsync(chn);

            await ctx.RespondAsync($"Connected to `{chn.Name}`");
        }
コード例 #3
0
        public async Task JoinVocal(CommandContext commandContext, DiscordChannel channel = null)
        {
            VoiceNextClient voiceNext = commandContext.Client.GetVoiceNextClient();

            if (voiceNext == null)
            {
                await commandContext.RespondAsync("voiceNext == null;");

                return;
            }
            VoiceNextConnection voiceConnection = voiceNext.GetConnection(commandContext.Guild);

            if (voiceConnection != null)
            {
                await commandContext.RespondAsync("already connected");

                return;
            }
            else
            {
                await commandContext.RespondAsync("bug bug bug");
            }

            DiscordVoiceState voiceState = commandContext.Member.VoiceState;

            if (voiceState.Channel == null && channel == null)
            {
                await commandContext.RespondAsync("you're not in a voice channel");

                return;
            }

            if (channel == null)
            {
                channel = voiceState.Channel;
            }

            await commandContext.RespondAsync($"Connected to {channel.Name}");

            voiceConnection = await voiceNext.ConnectAsync(channel);
        }
コード例 #4
0
        private async Task ContinuousPlay()
        {
            if (!File.Exists(fileToPlay))
            {
                return;
            }

            while (VNext == null)
            {
                await Task.Delay(100);
            }

            var voiceChannel = await _client.GetChannelAsync(451197681835048960);

            var vnc = await VNext.ConnectAsync(voiceChannel);

            // play
            Exception exc = null;
            await vnc.SendSpeakingAsync(true);

            try
            {
                var ffmpeg_inf = new ProcessStartInfo
                {
                    FileName               = "ffmpeg",
                    Arguments              = $"-i \"{fileToPlay}\" -ac 2 -f s16le -ar 48000 pipe:1",
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true
                };
                var ffmpeg = Process.Start(ffmpeg_inf);
                var ffout  = ffmpeg.StandardOutput.BaseStream;

                // let's buffer ffmpeg output
                using (var ms = new MemoryStream())
                {
                    await ffout.CopyToAsync(ms);

                    ms.Position = 0;

                    var buff = new byte[3840]; // buffer to hold the PCM data
                    var br   = 0;
                    while ((br = ms.Read(buff, 0, buff.Length)) > 0)
                    {
                        if (br < buff.Length) // it's possible we got less than expected, let's null the remaining part of the buffer
                        {
                            for (var i = br; i < buff.Length; i++)
                            {
                                buff[i] = 0;
                            }
                        }

                        await vnc.SendAsync(buff, 20); // we're sending 20ms of data
                    }
                }
            }
            catch (Exception ex) { exc = ex; }
            finally
            {
                await vnc.SendSpeakingAsync(false);
            }
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: BryanEggels/Discord-bot
        public static void addcommands(DiscordClient p_discord)
        {
            p_discord.UseCommands(new CommandConfig
            {
                Prefix  = "!",
                SelfBot = false,
            });
            UserRepository    userrepo = new UserRepository(new UserSQLContext());
            MessageRepository msgrepo  = new MessageRepository(new MessageSQLContext());

            p_discord.AddCommand("hello", async e =>
            {
                string[] msg = e.Message.Content.Split(' ');

                //if msg array contains more then 1 arrayobject then..
                if (msg.Length > 1 && msg[1].Length >= 3)

                {
                    bool ChannelContainsUser   = false;
                    List <DiscordUser> members = new List <DiscordUser>();
                    //check if member is in the current 'guild'
                    foreach (DiscordMember dm in e.Guild.Members)
                    {
                        //check if msg[1] containst a part of the user
                        if (dm.User.Username.ToUpper().Contains(msg[1].ToUpper()))
                        {
                            if (dm.User.Username.ToUpper() == msg[1].ToUpper())
                            {
                                ChannelContainsUser = true;
                                await e.Message.Respond($"{e.Message.Author.Username } says hello to <@{dm.User.ID}> ");
                                break;
                            }
                            members.Add(dm.User);
                        }
                        if (members.Count > 1 && !ChannelContainsUser)
                        {
                            await e.Message.Respond($"more then 1 user with those characters in his name");
                            ChannelContainsUser = true;
                            break;
                        }
                    }
                    if (members.Count == 1)
                    {
                        ChannelContainsUser = true;
                        await e.Message.Respond($"{e.Message.Author.Username } says hello to <@{members[0].ID}> ");
                    }
                    else if (!ChannelContainsUser)
                    {
                        await e.Message.Respond("That user is not in the current channel");
                    }
                }
                else
                {
                    await e.Message.Respond($"Hello, {e.Message.Author.Mention}!");
                }
            });
            p_discord.AddCommand("reken", async e =>
            {
                string[] msg = e.Message.Content.Split(' ');
                try
                {
                    double num1 = Convert.ToDouble(msg[1]);
                    double num2 = Convert.ToDouble(msg[3]);
                    double num3 = 1;
                    if (msg.Length > 4)
                    {
                        num3 = Convert.ToDouble(msg[4]);
                    }

                    switch (msg[2])
                    {
                    case "+":
                        await e.Message.Respond(num1.ToString() + msg[2] + num2.ToString() + '=' + (num1 + num2).ToString());
                        break;

                    case "-":
                        await e.Message.Respond(num1.ToString() + msg[2] + num2.ToString() + '=' + (num1 - num2).ToString());
                        break;

                    case "*":
                    case "x":
                        await e.Message.Respond(num1.ToString() + msg[2] + num2.ToString() + '=' + (num1 * num2).ToString());
                        break;

                    case "/":
                        await e.Message.Respond(num1.ToString() + msg[2] + num2.ToString() + '=' + (num1 / num2).ToString());
                        break;

                    case "**":
                    case "^":
                        await e.Message.Respond(num1.ToString() + msg[2] + num2.ToString() + '=' + Math.Pow(num1, num2).ToString());
                        break;

                    case "^^":
                        await e.Message.Respond(num1.ToString() + msg[2] + num2.ToString() + '=' + Math.Pow(Math.Pow(num1, num2), num3).ToString());
                        break;

                    case "%":
                        await e.Message.Respond(num1.ToString() + msg[2] + num2.ToString() + '=' + (num1 % num2).ToString());
                        break;

                    case ">":
                    case "<":
                    case "==":
                    case "!=":
                        await e.Message.Respond(msg[1] + " " + msg[2] + " " + msg[3] + " " + "= " + Operator(msg[2], num1, num2).ToString());
                        break;

                    default:
                        break;
                    }
                }
                catch (Exception exc)
                {
                    await e.Message.Respond(exc.Message);
                }
            });
            p_discord.AddCommand("join", async e =>
            {
                try
                {
                    var vcfg = new VoiceNextConfiguration
                    {
                        VoiceApplication = DSharpPlus.VoiceNext.Codec.VoiceApplication.Music
                    };
                    VoiceService = p_discord.UseVoiceNext(vcfg);

                    await VoiceService.ConnectAsync(await p_discord.GetChannelByID(272324215439491072));
                    Console.WriteLine("Joined voice channel");
                }
                catch (Exception exc)
                {
                    Console.WriteLine(exc.Message);
                }
            });
            p_discord.AddCommand("dc", async e =>
            {
                try
                {
                    DiscordGuild guild = await p_discord.GetGuild(e.Channel.GuildID);

                    VoiceService.GetConnection(guild).Disconnect();
                    VoiceService.GetConnection(guild).Dispose();
                }
                catch (Exception exc)
                {
                    Console.WriteLine(exc.Message);
                }
            });
            p_discord.AddCommand("god", async e =>
            {
                if (e.Message.Author.ID == 261216517910167554)
                {
                    await e.Message.Respond("AND THE REAL C#GOD IS....\n" + e.Message.Author.Username);
                }
                else
                {
                    await e.Message.Respond("you're not teh real c#god.");
                }
            });
            p_discord.AddCommand("kkk", async e =>
            {
                await e.Message.Respond($"WHITE POWER, RIGHT { e.Message.Author.Username }?");
            });
            p_discord.AddCommand("help", async e =>
            {
                string prefix = "!";
                await e.Message.Respond($"currently available commands are: \n{prefix}hello <username> \n{prefix}reken 'nummer' 'operator' 'nummer' \n{prefix}god to see if you are a c# god\n{prefix}karma @username to give a user karma!\n" +
                                        $"{prefix}dice 'minimumnumber' 'maximumnumber' (without the quotes) to generate a random number. {prefix}dice will automatically pick a number between 1 and 100.\n" +
                                        $"\n\nThis bot also functions as Robot9000. This means that the bot will mute you if you post duplicate content that already has been posted in this server.\n" +
                                        "The amount of time you get muted depends on the amount of punishments you already had.");
            });
            p_discord.AddCommand("666", async e =>
            {
                await e.Message.Respond("HAIL SATAN " + e.Message.Author.Username);
            });
            p_discord.AddCommand("blm", async e =>
            {
                await e.Message.Respond("BLACK HAS NO POWER, RIGHT " + e.Message.Author.Username + "?");
            });
            p_discord.AddCommand("play", async e =>
            {
                try
                {
                    DiscordGuild guild = await p_discord.GetGuild(e.Channel.GuildID);
                    var rand           = new Random();
                    var bytes          = new byte[32000];
                    rand.NextBytes(bytes);

                    await VoiceService.GetConnection(guild).SendAsync(bytes, 517, 16);
                    Console.Write("i just played something!");
                }
                catch (Exception exc)
                {
                    Console.WriteLine(exc.Message);
                }
            });
            p_discord.AddCommand("karma", async e =>
            {
                string[] msg             = e.Message.Content.Split(' ');
                List <DiscordUser> users = e.Message.Mentions;
                if (users.Count == 1)
                {
                    if (users[0].ID != e.Message.Author.ID)
                    {
                        int karma = AddKarma(users[0].ID);
                        await e.Message.Respond($"{users[0].Username} gained 1 karma!\n{users[0].Username} now has {karma} karma");
                    }
                    else
                    {
                        await e.Message.Respond($"You just lost 1 karma");
                    }
                }
                else if (users.Count > 1)
                {
                    await e.Message.Respond($"Please only mention 1 user :)");
                }
                else
                {
                    await e.Message.Respond($"You have to at least mention 1 user");
                }
            });
            p_discord.AddCommand("dice", async e =>
            {
                string[] msg = e.Message.Content.Split(' ');
                if (msg.Length > 1)
                {
                    int random = Dice(Convert.ToInt32(msg[1]), Convert.ToInt32(msg[2]));
                    await e.Message.Respond(random.ToString());
                }
                else if (msg.Length == 1)
                {
                    int random = Dice(1, 101);
                    await e.Message.Respond(random.ToString());
                }
                else
                {
                    await e.Message.Respond("Please use 2 parameters divided by a space");
                }
            });
            p_discord.AddCommand("unmute", async e =>
            {
                await Task.Delay(0);
                if (e.Message.Author.ID == 261216517910167554 || e.Message.Author.ID == 239471183475638272)
                {
                    if (e.Message.Mentions.Count > 0)
                    {
                        foreach (DiscordUser user in e.Message.Mentions)
                        {
                            new UserRepository(new UserSQLContext()).Unmute(user.ID);
                            await e.Message.Respond($"{e.Message.Author.Username } unmuted <@{user.ID}> ");
                        }
                    }
                    else
                    {
                        await e.Message.Respond($"Please mention the user(s) you want to unmute!");
                    }
                }
                else
                {
                    await e.Message.Respond($"You ar not permitted to unmute users!");
                }
            });
            p_discord.AddCommand("mutereset", async e =>
            {
                if (e.Message.Author.ID == 261216517910167554 || e.Message.Author.ID == 239471183475638272)
                {
                    if (userrepo.MuteCountreset())
                    {
                        userrepo.MuteReset();
                        await e.Message.Respond("Robot9000 mutes have been reset!");
                    }
                    else
                    {
                        await e.Message.Respond("Oops! looks like something went wrong. Please contact Mivo90");
                    }
                }
                else
                {
                    await e.Message.Respond("I'm sorry, I can not let you do that.");
                }
            });
            p_discord.AddCommand("messagereset", async e =>
            {
                if (e.Message.Author.ID == 261216517910167554 || e.Message.Author.ID == 239471183475638272)
                {
                    if (msgrepo.ResetMessages())
                    {
                        await e.Message.Respond("Robot9000 messages have been reset!");
                    }
                    else
                    {
                        await e.Message.Respond("Oops, couldn't reset the messages. Please contact Mivo90");
                    }
                }
                else
                {
                    await e.Message.Respond("Nice try.");
                }
            });
        }