Пример #1
0
        public async Task EvalCS(CommandContext ctx, [RemainingText] string code) // this command takes no arguments
        {
            await base.OperateCommand(ctx);

            var msg = ctx.Message;

            var cs1 = code.IndexOf("```") + 3;

            cs1 = code.IndexOf('\n', cs1) + 1;
            var cs2 = code.LastIndexOf("```");

            if (cs1 == -1 || cs2 == -1)
            {
                throw new ArgumentException("You need to wrap the code into a code block.");
            }

            var cs = code.Substring(cs1, cs2 - cs1);

            DiscordEmbed embed = JosephineEmbedBuilder.CreateEmbedMessage(ctx, null, "Evaluating...");

            msg = await ctx.RespondAsync("", false, embed).ConfigureAwait(false);

            try
            {
                var globals = new TestVariables(ctx.Message, ctx.Client, ctx);

                var sopts = ScriptOptions.Default;
                sopts = sopts.WithImports("System", "System.Collections.Generic", "System.Linq", "System.Text", "System.Threading.Tasks", "DSharpPlus", "DSharpPlus.CommandsNext", "DSharpPlus.Interactivity");
                sopts = sopts.WithReferences(AppDomain.CurrentDomain.GetAssemblies().Where(xa => !xa.IsDynamic && !string.IsNullOrWhiteSpace(xa.Location)));

                var script = CSharpScript.Create(cs, sopts, typeof(TestVariables));
                script.Compile();
                var result = await script.RunAsync(globals).ConfigureAwait(false);

                if (result != null && result.ReturnValue != null && !string.IsNullOrWhiteSpace(result.ReturnValue.ToString()))
                {
                    DiscordEmbed embedError0 = JosephineEmbedBuilder.CreateEmbedMessage(ctx, "Evaluation Result", result.ReturnValue.ToString(), null, new DiscordColor("#007FFF"));
                    await msg.ModifyAsync(embed : embedError0).ConfigureAwait(false);
                }
                else
                {
                    DiscordEmbed embedError1 = JosephineEmbedBuilder.CreateEmbedMessage(ctx, "Evaluation Successful", "No result was returned.", null, new DiscordColor("#007FFF"));
                    await msg.ModifyAsync(embed : embedError1).ConfigureAwait(false);
                }
            }
            catch (Exception ex)
            {
                DiscordEmbed embedError0 = JosephineEmbedBuilder.CreateEmbedMessage(ctx, "Evaluation Failure", string.Concat("**", ex.GetType().ToString(), "**: ", ex.Message), null, new DiscordColor("#FF0000"));
                await msg.ModifyAsync(embed : embedError0).ConfigureAwait(false);
            }
        }
Пример #2
0
 public async virtual Task executeAchievement(CommandContext ctx)
 {
     DiscordEmbed embed = JosephineEmbedBuilder.CreateEmbedMessage(ctx, name, description);
     await ctx.Message.RespondAsync("", false, embed);
 }
Пример #3
0
        public override async Task OperateCommand(CommandContext ctx, params string[] args)
        {
            await base.OperateCommand(ctx, args);

            string    subCommand = args[0];
            guildData data       = Utils.returnGuildData(ctx.Guild.Id);

            switch (subCommand.ToLower())
            {
            case "play":
                //Play the tunes!
                await VoiceJoin(ctx);

                //We need to download the spotify song or whatever
                if (args[1] != null)
                {
                    //Start to play the song
                    if (args[1].Contains("youtube") || args[1].Contains("youtu.be"))
                    {
                    }
                    else if (args[1].Contains("spotify"))
                    {
                        //Initialise the spotify bot if has not done yet!
                        if (api == null)
                        {
                            CredentialsAuth auth  = new CredentialsAuth("7c09a36e2ef84c2abc068c8979103d17", "d21bc05a3f604089b176e3b3e5975e0b");
                            Token           token = await auth.GetToken();

                            api = new SpotifyWebAPI
                            {
                                AccessToken = token.AccessToken,
                                TokenType   = token.TokenType
                            };
                        }

                        string uriCode = null;
                        Uri    uri     = new UriBuilder(args[1]).Uri;

                        if (args[1] != null)
                        {
                            //Get the spotify track from url or the uri code
                            uriCode = uri.Segments[2];
                        }

                        if (uriCode != null)
                        {
                            if (uri.Segments[1] == "track")
                            {
                                FullTrack track = await api.GetTrackAsync(uriCode);

                                if (track.Artists != null)
                                {
                                    List <string> artists = new List <string>();
                                    foreach (SimpleArtist artist in track.Artists)
                                    {
                                        artists.Add(artist.Name);
                                    }
                                    string connectArtist = string.Join(",", artists.ToArray());
                                    await ctx.RespondAsync("Playing: " + track.Name + " By: " + connectArtist);
                                }
                                if (track.HasError())
                                {
                                    await ctx.RespondAsync("The track when playing had an issue!");
                                }
                            }
                            else if (uri.Segments[1] == "playlist")
                            {
                                //Playlist
                                FullPlaylist list = await api.GetPlaylistAsync(uriCode);

                                await ctx.RespondAsync("Playing: " + list.Name);

                                if (list.HasError())
                                {
                                    await ctx.RespondAsync("The playlist had and issue");
                                }
                            }
                        }
                        else
                        {
                            await ctx.RespondAsync("Invalid url or uri code");
                        }
                    }
                }
                else
                {
                    await ctx.RespondAsync("No song link was defined!");
                }
                break;

            case "stop":
                //Stop the tunes!

                break;

            case "leave":
            case "fuckoff":
                //Leave the channel forcefully!
                await VoiceLeave(ctx);

                break;

            case "autoleave":
                //Set if the bot should automatically leave the voice channel when no one is in the voice channel
                if (data.autoSongLeave == false)
                {
                    data.autoSongLeave = true;
                    await ctx.RespondAsync("This bot will leave the party when everyone else has finished!");
                }
                else if (data.autoSongLeave == true)
                {
                    data.autoSongLeave = false;
                    await ctx.RespondAsync("This bot will keep on partying!");
                }
                break;

            case "loop":
                //loop the song that is currently playing
                if (data.loopSong == false)
                {
                    data.loopSong = true;
                    await ctx.RespondAsync("Looping Song !");
                }
                else if (data.loopSong == true)
                {
                    data.loopSong = false;
                    await ctx.RespondAsync("Not Looping Song!");
                }
                break;

            default:
            case "help":
                //Show the help on it.
                Dictionary <string, string> argumentsHelp = new System.Collections.Generic.Dictionary <string, string>();
                argumentsHelp.Add(";;song play", "specify a song right after play with a space then this bot will play or specify a link (overrides queue)");
                argumentsHelp.Add(";;song stop", "stop whatever is playing");
                argumentsHelp.Add(";;song leave", "forces the bot to leave the current voice channel");
                argumentsHelp.Add(";;song autoleave", "turns on auto leave the bot will leave the channel when no one is present");
                argumentsHelp.Add(";;song loop", "loops the current song and disables queue");
                DiscordEmbed embedHelp = JosephineEmbedBuilder.CreateEmbedMessage(ctx, "Sub-Commands", "for ';;announce set'", null, JosephineBot.defaultColor, argumentsHelp, false);
                await ctx.RespondAsync("Go to http://discord.rickasheye.xyz/ for all sub-commands", false, embedHelp);

                break;
            }
        }