Exemplo n.º 1
0
        public async Task SuggestAsync([Remainder] string suggestion)
        {
            if (CommandHandler.FeatureFlagDisabled(FeatureFlag.SUGGEST))
            {
                return;
            }
            var suggestionsChannel = Context.Guild.GetTextChannel(Global.PostTargets[PostTarget.SUGGESTIONS]);
            var user = Context.Message.Author;

            if (suggestion.Contains("@everyone") || suggestion.Contains("@here"))
            {
                return;
            }

            var embed = new EmbedBuilder()
                        .WithColor(9896005)
                        .WithDescription(suggestion)
                        .WithFooter(user.ToString());

            if (Context.Message.Attachments.Count > 0)
            {
                embed.WithImageUrl(Context.Message.Attachments.ToList()[0].ProxyUrl);
            }

            var oldmessage = await suggestionsChannel.EmbedAsync(embed);

            await oldmessage.AddReactionsAsync(new IEmote[]
            {
                StoredEmote.GetEmote(Global.OnePlusEmote.OP_NO),
                StoredEmote.GetEmote(Global.OnePlusEmote.OP_YES)
            });
        }
Exemplo n.º 2
0
        private String BuildStringForPoster(KeyValuePair <ulong, int>[] values, List <String> badges)
        {
            var stringBuilder = new StringBuilder();

            for (var index = 0; index < badges.Count(); index++)
            {
                if (index >= values.Count())
                {
                    continue;
                }
                var element = values.ElementAt(index);

                var user          = Extensions.GetUserById(element.Key);
                var userReference = user != null ? user.Mention : "User left the server. " + element.Key;

                stringBuilder.Append(badges[index]);
                stringBuilder.Append(" - ");
                stringBuilder.Append(element.Value);
                stringBuilder.Append(" ");
                stringBuilder.Append(StoredEmote.GetEmote(Global.OnePlusEmote.STAR));
                stringBuilder.Append(" ");
                stringBuilder.Append(userReference);
                stringBuilder.Append(Environment.NewLine);
            }
            return(stringBuilder.ToString());
        }
        /// <summary>
        /// Updates the state of the given profanity report in the database as either valid or not valid, dependingn on which reaction was added
        /// After this is executed once for a given message, and the votes cast are over a certain threshold (yes or no) this method will either delete the message
        /// or remove it only from the runtime data structure
        /// </summary>
        /// <param name="message">The <see cref="Discord.IUserMessage"> object containing the profanity report at which the reaction was added</param>
        /// <param name="channel">The <see cref="Discord.WebSocket.ISocketMessageChannel"> channel in which the profanity was reported to</param>
        /// <param name="reaction">The <see cref="Discord.WebSocket.SocketReaction"> object containing the added reaction</param>
        /// <returns></returns>
        public async Task Execute(IUserMessage message, ISocketMessageChannel channel, SocketReaction reaction)
        {
            var noEmote  = StoredEmote.GetEmote(Global.OnePlusEmote.OP_NO);
            var yesEmote = StoredEmote.GetEmote(Global.OnePlusEmote.OP_YES);

            using (var db = new Database())
            {
                var profanityLq = db.Profanities.AsQueryable().Where(prof => prof.ReportMessageId == message.Id);
                if (profanityLq.Any())
                {
                    if (reaction.Emote.Name == noEmote.Name || reaction.Emote.Name == yesEmote.Name)
                    {
                        var profanity = profanityLq.First();
                        ReactionMetadata yesReaction = message.Reactions.Where(re => re.Key.Name == yesEmote.Name).First().Value;
                        var yesCount = yesReaction.ReactionCount;
                        if (yesReaction.IsMe)
                        {
                            yesCount -= 1;
                        }

                        ReactionMetadata noReaction = message.Reactions.Where(re => re.Key.Name == noEmote.Name).First().Value;
                        var noCount = noReaction.ReactionCount;
                        if (noReaction.IsMe)
                        {
                            noCount -= 1;
                        }
                        if (yesCount >= Global.ProfanityVoteThreshold)
                        {
                            profanity.Valid = true;
                            var guild          = Global.Bot.GetGuild(Global.ServerID);
                            var profaneMessage = await guild.GetTextChannel(profanity.ChannelId).GetMessageAsync(profanity.MessageId);

                            if (profaneMessage != null)
                            {
                                if (profaneMessage is RestUserMessage)
                                {
                                    var castedProfaneMessage = profaneMessage as RestUserMessage;
                                    await castedProfaneMessage.DeleteAsync();
                                }
                                else if (profaneMessage is SocketUserMessage)
                                {
                                    var castedProfaneMessage = profaneMessage as SocketUserMessage;
                                    await castedProfaneMessage.DeleteAsync();
                                }
                            }
                            Global.ReportedProfanities.Remove(Global.ReportedProfanities.Where(g => g.ProfanityId == profanity.ProfanityId).FirstOrDefault());
                        }
                        if (noCount >= Global.ProfanityVoteThreshold)
                        {
                            Global.ReportedProfanities.Remove(Global.ReportedProfanities.Where(g => g.ProfanityId == profanity.ProfanityId).FirstOrDefault());
                        }
                    }
                }
                db.SaveChanges();
            }
            await Task.CompletedTask;
        }
        /// <summary>
        /// Returns the actual star count on a message (the count of star reactions without the author)
        /// </summary>
        /// <param name="message">The <see cref="Discord.IUserMessage"> object to get the star count for</param>
        /// <param name="starReaction">The pair of the reaction with the reaction metadata of the current reaction which was just added</param>
        /// <returns>The amount of reactions besides the original author of the message</returns>
        private async Task <int> GetTrueStarCount(IUserMessage message, KeyValuePair <IEmote, ReactionMetadata> starReaction)
        {
            var reactions      = message.GetReactionUsersAsync(StoredEmote.GetEmote(Global.OnePlusEmote.STAR), starReaction.Value.ReactionCount);
            var validReactions = 0;
            await reactions.ForEachAsync(collection =>
            {
                foreach (var user in collection)
                {
                    if (user.Id != message.Author.Id)
                    {
                        validReactions += 1;
                    }
                }
            });

            return(validReactions);
        }
        /// <summary>
        /// Builds the message of a starboard message containing the messageID, the channel of th epost, the star count and an emote.
        /// </summary>
        /// <param name="message"></param>
        /// <param name="reactionInfo"></param>
        /// <param name="reaction"></param>
        /// <param name="starCount"></param>
        /// <returns></returns>
        private string GetStarboardMessage(IUserMessage message, KeyValuePair <IEmote, ReactionMetadata> reactionInfo, IReaction reaction, int starCount)
        {
            var emote = StoredEmote.GetEmote(Global.OnePlusEmote.STAR);

            if (starCount >= (int)Global.Level2Stars)
            {
                emote = StoredEmote.GetEmote(Global.OnePlusEmote.LVL_2_STAR);
            }
            if (starCount >= (int)Global.Level3Stars)
            {
                emote = StoredEmote.GetEmote(Global.OnePlusEmote.LVL_3_STAR);
            }
            if (starCount >= (int)Global.Level4Stars)
            {
                emote = StoredEmote.GetEmote(Global.OnePlusEmote.LVL_4_STAR);
            }
            return($"{emote} {starCount} <#{message.Channel.Id}> ID: {message.Id}");
        }
Exemplo n.º 6
0
 public async Task <RuntimeResult> SetTrackingStatus(string name, Boolean value)
 {
     if (CommandHandler.FeatureFlagDisabled(FeatureFlag.EMOTE_TRACKING))
     {
         return(CustomResult.FromIgnored());
     }
     using (var db = new Database())
     {
         var sameKey = db.Emotes.AsQueryable().Where(e => e.Key == name);
         if (sameKey.Any())
         {
             StoredEmote emoteToChange = sameKey.First();
             emoteToChange.TrackingDisabled = value;
             db.SaveChanges();
             return(CustomResult.FromSuccess());
         }
         else
         {
             return(CustomResult.FromError("Emote not found."));
         }
     }
 }
Exemplo n.º 7
0
        public async Task <RuntimeResult> CreateEmoteInDatabase(string name, [Remainder] string _)
        {
            var emoteTags = Context.Message.Tags.Where(t => t.Type == TagType.Emoji);

            if (!emoteTags.Any())
            {
                return(CustomResult.FromError("No emote found."));
            }
            var uncastedEmote = emoteTags.Select(t => (Emote)t.Value).First();

            if (uncastedEmote is Emote)
            {
                var emote = uncastedEmote as Emote;
                using (var db = new Database())
                {
                    var         sameKey = db.Emotes.AsQueryable().Where(e => e.Key == name);
                    StoredEmote emoteToChange;
                    if (sameKey.Any())
                    {
                        emoteToChange = sameKey.First();
                    }
                    else
                    {
                        emoteToChange = new StoredEmote();
                        db.Emotes.Add(emoteToChange);
                    }
                    emoteToChange.Animated = emote.Animated;
                    emoteToChange.EmoteId  = emote.Id;
                    emoteToChange.Name     = emote.Name;
                    emoteToChange.Key      = name;
                    emoteToChange.Custom   = true;
                    db.SaveChanges();
                }
            }

            await Task.CompletedTask;

            return(CustomResult.FromSuccess());
        }
Exemplo n.º 8
0
        public async Task ExecuteQuery([Remainder] string query)
        {
            var server = Environment.GetEnvironmentVariable("Server");
            var db     = Environment.GetEnvironmentVariable("Database");
            var uid    = Environment.GetEnvironmentVariable("Uid");
            var pwd    = Environment.GetEnvironmentVariable("Pwd");

            if (server == null || db == null || uid == null || pwd == null)
            {
                throw new Exception("Cannot find MySQL connection string in EnvVar.");
            }

            var connStr = new MySqlConnectionStringBuilder
            {
                Server   = server,
                Database = db,
                UserID   = uid,
                Password = pwd
            };

            try
            {
                using (var connection = new MySqlConnection())
                {
                    connection.ConnectionString = connStr.ToString();
                    connection.Open();

                    using (var sql = new MySqlCommand(query, connection))
                    {
                        await sql.ExecuteNonQueryAsync();
                    }
                }
                await Context.Message.AddReactionAsync(StoredEmote.GetEmote(Global.OnePlusEmote.SUCCESS));
            }
            catch
            {
                await Context.Message.AddReactionAsync(new Emoji("\u274C"));
            }
        }
Exemplo n.º 9
0
        private String BuildStringForMessage(Data.Models.StarboardMessage[] values, List <String> badges)
        {
            var starBoardChannelId = Global.PostTargets[PostTarget.STARBOARD];
            var stringBuilder      = new StringBuilder();

            for (var index = 0; index < badges.Count(); index++)
            {
                if (index >= values.Count())
                {
                    continue;
                }
                var element = values.ElementAt(index);
                stringBuilder.Append(badges[index]);
                stringBuilder.Append(" - ");
                stringBuilder.Append(element.Starcount);
                stringBuilder.Append(" ");
                stringBuilder.Append(StoredEmote.GetEmote(Global.OnePlusEmote.STAR));
                stringBuilder.Append(" ");
                stringBuilder.Append(Extensions.GetMessageUrl(Global.ServerID, starBoardChannelId, element.StarboardMessageId, "Jump!"));
                stringBuilder.Append(Environment.NewLine);
            }
            return(stringBuilder.ToString());
        }
        public override async Task Execute(IUserMessage message, ISocketMessageChannel channel, SocketReaction reaction)
        {
            await base.Execute(message, channel, reaction);

            using (var db = new Database())
            {
                if (this.TriggeredThreshold)
                {
                    var currentStarReaction = message.Reactions.Where(re => re.Key.Name == reaction.Emote.Name).DefaultIfEmpty().First();
                    var reactions           = message.GetReactionUsersAsync(StoredEmote.GetEmote(Global.OnePlusEmote.STAR), currentStarReaction.Value.ReactionCount);
                    await reactions.ForEachAsync(collection =>
                    {
                        foreach (var user in collection)
                        {
                            var starerRelation       = new StarboardPostRelation();
                            starerRelation.UserId    = user.Id;
                            starerRelation.MessageId = message.Id;
                            db.StarboardPostRelations.Add(starerRelation);
                        }
                    });

                    if (reaction.User.IsSpecified)
                    {
                        var notificationMessage = "User caused a starboard post to reach the threshold.";
                        await base.SendNotification(notificationMessage, reaction.User.Value, message);
                    }
                }
                else if (this.RelationAdded)
                {
                    var starerRelation = new StarboardPostRelation();
                    starerRelation.UserId    = reaction.UserId;
                    starerRelation.MessageId = message.Id;
                    db.StarboardPostRelations.Add(starerRelation);
                }
                db.SaveChanges();
            }
        }
Exemplo n.º 11
0
        public async Task ShutdownAsync()
        {
            await Context.Message.AddReactionAsync(StoredEmote.GetEmote(Global.OnePlusEmote.SUCCESS));

            Environment.Exit(0);
        }
 public bool ActionApplies(IUserMessage message, ISocketMessageChannel channel, SocketReaction reaction)
 {
     return(reaction.Emote.Equals(StoredEmote.GetEmote(Global.OnePlusEmote.STAR)) && message.Author.Id != reaction.UserId && CommandHandler.FeatureFlagEnabled(FeatureFlag.STARBOARD));
 }