示例#1
0
        /// <summary>
        /// Gets the warnings of a certain user by page (maximum of 5 logs per page).
        /// </summary>
        /// <param name="context">Gives the context needed to execute the command.</param>
        /// <param name="mentionedUser">Gives the user of whom the warnings need to be checked.</param>
        /// <param name="page">Gives the page the user wants to view.</param>
        public async Task GetWarnings(SocketCommandContext context, SocketGuildUser mentionedUser, int page)
        {
            var mongoDbHandler = new MongoDBHandler(context.Guild.Id.ToString());
            var userLog        =
                mongoDbHandler.LoadRecordByField <UserLogsModel>("Logs", "_id", Convert.ToInt64(mentionedUser.Id));


            if (userLog == null)
            {
                await context.Channel.SendMessageAsync("This user has no logs!");

                return;
            }

            var builder = new EmbedBuilder();

            builder.WithAuthor(mentionedUser.Username, mentionedUser.GetAvatarUrl());
            builder.WithColor(255, 183, 229);

            var actions = userLog.Actions;

            //Calculates the amount of possible pages
            var maxPages = Math.Ceiling(Convert.ToDouble(actions.Count) / 5) - 1;

            //Checks if the current given page is possible to reach
            page = page > maxPages ? (int)maxPages : page;

            //Loops the logs of the given pages
            for (var i = page * 5; i < page * 5 + 5; i++)
            {
                if (actions.Count > i)
                {
                    builder.AddField("Case: [" + i + "] - " + actions[i].GetActionType(), actions[i].GetReason());
                    continue;
                }
                break;
            }

            builder.WithFooter("Page " + (page + 1) + "/" + (maxPages + 1));
            await context.Channel.SendMessageAsync("", false, builder.Build());
        }
示例#2
0
        /// <summary>
        /// Sends a interaction in the form of a type of media.
        /// </summary>
        /// <param name="context">Gives the context needed to execute the command.</param>
        /// <param name="type">Gives the form of interaction a user wants to perform.</param>
        /// <param name="mentionedUser">Gives the user the interaction is performed on.</param>
        /// <param name="actionLine">Gives a line that describes what interaction has been performed.</param>
        public async Task PostInteraction(SocketCommandContext context, string type, SocketGuildUser mentionedUser, string actionLine)
        {
            var mongoDbHandler = new MongoDBHandler("MediaStorage");

            //Gets a random media from the database of the given interaction type
            var mediaStorage = mongoDbHandler.LoadRecordByField <MediaModel>("Interactions", "MediaType", type);
            var random       = new Random();
            var index        = random.Next(0, mediaStorage.MediaItems.Length);

            var user = context.User as SocketGuildUser;

            if (user == null)
            {
                //todo: error handle
                return;
            }

            var builder = new EmbedBuilder();

            builder.WithColor(255, 183, 229);
            builder.WithImageUrl(mediaStorage.MediaItems[index]);
            builder.WithDescription("**" + mentionedUser.Username + "** " + actionLine + " **" + user.Username + "**");
            await context.Channel.SendMessageAsync("", false, builder.Build());
        }