public async ValueTask <CommandResult> HandleAsync(ICommandContext context) { var message = await DiscordMessageHelper.FromLinkAsync(context.Guild, MessageLink); if (message is null) { return(CommandResult.InvalidParameter("Invalid message link.")); } var emoji = DiscordEmojiHelper.Parse(context.Client, EmojiText); if (emoji is null) { return(CommandResult.InvalidParameter("Invalid emoji.")); } // TODO: Check if there will be collision in db and show the user nice error message. var reactionRole = new ReactionRole(message, emoji, Role); await _unitOfWork.ReactionRoles.AddAsync(reactionRole); await message.CreateReactionAsync(emoji); await _unitOfWork.CompleteAsync(); var messageLink = Markdown.Link("message", message.JumpLink.ToString()); return(CommandResult.Success($"Added self-assignable role {Role.Mention} with emoji {emoji} to {messageLink}.")); }
public async ValueTask <CommandResult> HandleAsync(ICommandContext context) { var embed = new DiscordEmbedBuilder { Author = new DiscordEmbedBuilder.EmbedAuthor { Name = context.User.Username, IconUrl = context.User.AvatarUrl }, Description = Question, Color = context.Member.Color }; var builder = new DiscordFollowupMessageBuilder() .AddEmbed(embed); if (TargetRole is not null) { builder .WithContent(TargetRole.Mention) .AddMention(new RoleMention(TargetRole)); } var message = await context.RespondAsync(builder); var emoteYes = DiscordEmojiHelper.Parse(context.Client, UrfRidersEmotes.Checkmark); var emoteNo = DiscordEmojiHelper.Parse(context.Client, UrfRidersEmotes.Crossmark); _ = message.CreateReactionAsync(emoteYes); _ = message.CreateReactionAsync(emoteNo); // TODO: Show list of users that reacted in the message. return(CommandResult.NoAction); }
public async Task MainAsync() { _client = new DiscordSocketClient(); _client.Log += Log; var token = JObject.Parse(File.ReadAllText(@"../../../../config.json"))["token"].ToString(); await _client.LoginAsync(TokenType.Bot, token); await _client.StartAsync(); _discordEmojis = DiscordEmojiHelper.GetAllAvailableEmojis(); SetRandomEmoji(); _client.MessageReceived += MessageRecieved; // Block this task until the program is closed await Task.Delay(-1); }
// TODO: Maybe do this in another class private void SetRandomEmoji() { _emoji = DiscordEmojiHelper.GetRandomEmoji(_discordEmojis); }