Inheritance: System.EventArgs
Ejemplo n.º 1
0
            public static async Task Execute(string booru, Commands.CommandEventArgs e)
            {
                var tags  = string.Join(" ", e.Args);
                var board = Get(booru, tags);

                for (int i = 10; i != 0; --i)
                {
                    try
                    {
                        int posts = board.GetPostCount();
                        if (board._type == Type.E621)
                        {
                            posts = Math.Min(320 * 750, posts);                           // Clamp before randomization for userfacing random.
                        }
                        if (posts == 0)
                        {
                            await Helpers.SendEmbed(e, $"There is nothing under the tag(s):\n{tags}\non {booru}. Please try something else.");
                        }
                        else
                        {
                            await Helpers.SendEmbed(e, board.GetEmbed(posts == 1 ? 0 : new Random().Next(0, posts - 1)));
                        }
                        return;
                    }
                    catch (Exception ex) { await Log.Write(Discord.LogSeverity.Warning, "", ex, booru); }
                }
                await e.Channel.SendMessageAsync($"Failed ten times, something must be broken with {booru}'s API.");
            }
Ejemplo n.º 2
0
            bool Triad(Commands.CommandEventArgs e, SoundCloud.NET.Models.Track track, bool multiple, bool say_added = false)
            {
                var pl    = playlist[e.User.VoiceChannel.Id];
                var title = $"{track.Title} by {track.User.Username}";

                if (!track.Streamable)
                {
                    if (multiple)
                    {
                        e.Channel.SendMessage($"{title} is not streamable.");
                    }
                    return(false);
                }
                var ext = $"{title} (**{track.PermalinkUrl}**)";

                if (pl.TryInsert(new Song($"{track.StreamUrl}?client_id={ClientID}", Song.EType.SoundCloud, e.User, ext)))
                {
                    if (!say_added)
                    {
                        e.Channel.SendMessage($"{title} added to the playlist.");
                    }
                    return(true);
                }
                if (multiple)
                {
                    e.Channel.SendMessage($"{title} is already in the playlist.");
                }
                return(false);
            }
Ejemplo n.º 3
0
 internal async Task Reset(Commands.CommandEventArgs e)
 {
     if (!exit && AddVote(votes[(int)Vote.Reset], e, "reset the stream", "resetting stream", "reset"))
     {
         await streams.Reset(e.User.VoiceChannel);
     }
 }
Ejemplo n.º 4
0
 internal void Skip(Commands.CommandEventArgs e)
 {
     if (!skip && AddVote(votes[(int)Vote.Skip], e, "skip current song", "skipping song", "skip"))
     {
         SkipSongs();
     }
 }
Ejemplo n.º 5
0
 internal void Encore(Commands.CommandEventArgs e)
 {
     if (EncoreVote(e))
     {
         DoEncore();
     }
 }
Ejemplo n.º 6
0
 internal void InsertFile(string file, Commands.CommandEventArgs e)
 {
     lock (this)
     {
         var i     = NonrequestedIndex();
         var cur_i = FindIndex(song => song.Uri == file);
         if (cur_i != -1)
         {
             if (i > cur_i)
             {
                 if (cur_i == 0)
                 {
                     if (EncoreVote(e))
                     {
                         InsertEncore();
                     }
                 }
                 else
                 {
                     e.Channel.SendMessage($"{e.User.Mention} Your request is already in the playlist at {cur_i}.");
                 }
                 return;
             }
             RemoveAt(cur_i);
         }
         Insert(i, new Song(file, Song.EType.Request, e.User));
     }
 }
Ejemplo n.º 7
0
            static bool Triad(Commands.CommandEventArgs e, VideoData video)
            {
                bool ret = playlist[e.User.VoiceChannel.Id].TryInsert(new Song(video.Uri, Song.EType.Youtube, e.User, video.Title + (video.Link == null ? "" : $" ({video.Link})")));

                e.Channel.SendMessage(ret ? $"{video.Title} added to the playlist."
                        : $"{e.User.Mention} Your request ({video.Title}) is already in the playlist.");
                return(ret);
            }
Ejemplo n.º 8
0
            internal async Task Play(Commands.CommandEventArgs e, bool request, Stream stream = null)
            {
                SQL.AddOrUpdateFlag(e.User.VoiceChannel.Id, "music", request ? "2" : "1");
                if (stream != null)
                {
                    stream.Request = request;
                }
                else
                {
                    await streams.Stop(e.Server);

                    await streams.AddStream(e.User.VoiceChannel, request);
                }
            }
Ejemplo n.º 9
0
            private SoundCloud.NET.Models.BaseModel[] Search(Commands.CommandEventArgs e, bool is_playlist, int desired = 0)
            {
                var search = new SoundCloud.NET.SearchParameters(string.Join(" ", desired != 0 ? e.Args.Skip(1) : e.Args))
                {
                    Limit = 200, Streamable = true
                };
                var container = is_playlist ? (SoundCloud.NET.Models.BaseModel[])SearchPlaylist(search) : SearchTrack(search, desired != 0 ? desired : 500);

                if (container.Count() == 0)
                {
                    e.Channel.SendMessage($"{e.User.Mention} Your request was not found.");
                    return(null);
                }
                return(container);
            }
Ejemplo n.º 10
0
            public static async Task Execute(string booru, Commands.CommandEventArgs e)
            {
                var tags  = string.Join(" ", e.Args);
                var board = Get(booru, tags);

                for (int i = 10; i != 0; --i)
                {
                    try
                    {
                        int posts = board.GetPostCount();
                        await e.Channel.SendMessage(posts == 0?
                                                    $"There is nothing under the tag(s):\n{tags}\non {booru}. Please try something else." :
                                                    board.GetImageLink(posts == 1 ? 0 : new Random().Next(1, posts - 1)));

                        return;
                    }
                    catch { }
                }
                await e.Channel.SendMessage($"Failed ten times, something must be broken with {booru}'s API.");
            }
Ejemplo n.º 11
0
 internal bool AddVote(List <ulong> vote, Commands.CommandEventArgs e, string action, string success, string actionshort)
 {
     lock (vote)
         if (!vote.Contains(e.User.Id))
         {
             vote.Add(e.User.Id);
             var listeners = e.User.VoiceChannel.Users.Count() - 1;
             var needed    = Math.Ceiling((float)listeners / 2);
             if (vote.Count == needed)
             {
                 e.Channel.SendMessage($"{vote.Count}/{listeners} votes to {action}. 50%+ achieved, {success}...");
                 return(true);
             }
             else if (vote.Count < needed)
             {
                 e.Channel.SendMessage($"{vote.Count}/{listeners} votes to {action}. (Needs 50% or more to {actionshort})");
             }
         }
     return(false);
 }
Ejemplo n.º 12
0
            int Triad(Commands.CommandEventArgs e, SoundCloud.NET.Models.Playlist playlist, bool multiple, bool say_added = false)
            {
                int ret = 0; // playlist.TrackCount includes unplayable tracks.

                foreach (var track in playlist.Tracks)
                {
                    if (Triad(e, track, false, true))
                    {
                        ++ret;
                    }
                }
                if (!say_added)
                {
                    if (ret != 0)
                    {
                        e.Channel.SendMessage($"The contents of {playlist.Title} by {playlist.User.Username} ({ret} tracks) have been added to the playlist.");
                    }
                    else if (!multiple)
                    {
                        e.Channel.SendMessage($"There is nothing in {playlist.Title} that isn't already in the playlist.");
                    }
                }
                return(ret);
            }
Ejemplo n.º 13
0
 public CommandErrorEventArgs(CommandErrorType errorType, CommandEventArgs baseArgs, Exception ex)
     : base(baseArgs.Message, baseArgs.Command, baseArgs.Args)
 {
     Exception = ex;
     ErrorType = errorType;
 }
Ejemplo n.º 14
0
 internal void Repeat(Commands.CommandEventArgs e)
 {
     e.Channel.SendMessage($"Turning {(repeat ? "off" : "on")} repeat mode for stream...");
     repeat = !repeat;
 }
Ejemplo n.º 15
0
 internal void Pause(Commands.CommandEventArgs e)
 {
     e.Channel.SendMessage($"{(pause ? "Resum" : "Paus")}ing stream...");
     pause = !pause;
 }
Ejemplo n.º 16
0
 bool EncoreVote(Commands.CommandEventArgs e)
 => AddVote(votes[(int)Vote.Encore], e, "replay current song", "song will be replayed", "replay");