internal static async Task UserSentMessage(SocketGuildUser user, SocketTextChannel channel) { var userAccount = UserAccounts.UserAccounts.GetAccount(user); // get user that just typed uint oldLevel = userAccount.LevelNumber; // store their previous level userAccount.XP += 10; // add the xp UserAccounts.UserAccounts.SaveAccounts(); //save uint newLevel = userAccount.LevelNumber; // store their current level if (oldLevel != newLevel) // if old level not equal to new level they must have gained a level { var embed = new EmbedBuilder // create new embed { Color = new Color(255, 82, 41), // embed colour (orange) Author = new EmbedAuthorBuilder // create new author within embed (used as a title when displayed) { Name = user.Username + " just levelled up!", // author text IconUrl = "http://cdn.edgecast.steamstatic.com/steamcommunity/public/images/avatars/ea/ea879dd914a94d7f719bb553306786fa5ae6acb0_full.jpg" // duckybot logo, displayed beside author text } }; embed.AddField("LEVEL", newLevel, true); // users current level embed.AddField("Current XP", userAccount.XP, true); // users current xp await channel.SendMessageAsync(embed.ToString()); // post embed } }
[Summary("Shows a list of all available commands per module, and a brief description of what they do. :nerd:")] // command summary public async Task HelpAsync() // command async task (method basically) { var dmChannel = await Context.User.GetOrCreateDMChannelAsync(); // A direct messages channel is created so that the !help command content will be privately sent to the user & not flood the chat var builder = new EmbedBuilder // create new embed { Color = new Color(255, 82, 41), // embed colour (orange) Author = new EmbedAuthorBuilder // create new author within embed (used as a title when displayed) { Name = "The DuckyBot commands must be typed precisely as shown below:-", // author text IconUrl = "http://cdn.edgecast.steamstatic.com/steamcommunity/public/images/avatars/ea/ea879dd914a94d7f719bb553306786fa5ae6acb0_full.jpg" // duckybot logo, displayed beside author text } }; foreach (var module in _service.Modules) // loop through the modules taken from the command service initiated earlier! { // string description = null; // description defaults to null to ensure no errors occur if the description building fails var description = new StringBuilder(); foreach (var cmd in module.Commands) // loop through all the commands per module as well { var result = await cmd.CheckPreconditionsAsync(Context); // gotta check if they pass if (result.IsSuccess) // if they DO pass { description.AppendLine($"`!{cmd.Aliases.First()}`" + $" - {cmd.Summary}"); // ADD that command's first alias (aka it's actual name) to the description tag of this embed, along with the set bot command prefix and a summary of the command } } if (!string.IsNullOrWhiteSpace(description.ToString())) // if the module wasn't empty add a field where we drop all the command data into! { builder.AddField(x => // add field with multiple properties defined { x.Name = module.Name; // module name x.Value = description; // above description format for each command x.IsInline = false; // not inline (so it appears like a list) }); } } await dmChannel.SendMessageAsync("", false, builder.Build()); // then send embed to the user in the direct messages channel await Context.Channel.SendMessageAsync(Context.User.Mention + " Check your direct messages for a list of my commands! <:duckybot:378960915116064768> "); // reply to user in the channel they used the !help command to notify them of the direct message }