public async Task Dialogue(CommandContext ctx) { TextStep inputStep = new TextStep("Enter something interesting", null); TextStep funnyStep = new TextStep("Haha, funny", null); string input = string.Empty; inputStep.OnValidResult += (result) => { input = result; if (result == "something interesting") { inputStep.SetNextStep(funnyStep); } }; DiscordDmChannel userChannel = await ctx.Member.CreateDmChannelAsync().ConfigureAwait(false); DialogueHandler inputDialogueHandler = new DialogueHandler(ctx.Client, userChannel, ctx.User, inputStep); bool succeeded = await inputDialogueHandler.ProcessDialogue().ConfigureAwait(false); if (!succeeded) { return; } await ctx.Channel.SendMessageAsync(input).ConfigureAwait(false); }
public async Task EmojiDialogue(CommandContext ctx) { TextStep yesStep = new TextStep("You chose yes", null); TextStep noStep = new TextStep("You chose no", null); ReactionStep emojiStep = new ReactionStep("Yes or No?", new Dictionary <DiscordEmoji, ReactionStepData> { { DiscordEmoji.FromName(ctx.Client, ":+1:"), new ReactionStepData { Content = "This means yes", NextStep = yesStep } }, { DiscordEmoji.FromName(ctx.Client, ":-1:"), new ReactionStepData { Content = "This means no", NextStep = noStep } } }); DiscordDmChannel userChannel = await ctx.Member.CreateDmChannelAsync().ConfigureAwait(false); DialogueHandler inputDialogueHandler = new DialogueHandler(ctx.Client, userChannel, ctx.User, emojiStep); bool succeeded = await inputDialogueHandler.ProcessDialogue().ConfigureAwait(false); if (!succeeded) { return; } }
public async Task WarnAsync(CommandContext ctx, [Description("Member.")] DiscordMember member, [RemainingText, Description("Warning message.")] string msg = null) { var emb = new DiscordEmbedBuilder() { Title = "Warning received!", Description = $"Guild {Formatter.Bold(ctx.Guild.Name)} issued a warning to you through me.", Color = DiscordColor.Red, Timestamp = DateTime.Now }; if (!string.IsNullOrWhiteSpace(msg)) { emb.AddField("Warning message", msg); } try { DiscordDmChannel dm = await member.CreateDmChannelAsync(); await dm.SendMessageAsync(embed : emb.Build()); } catch { throw new CommandFailedException("I can't talk to that user..."); } await this.InformAsync(ctx, $"Successfully warned member {Formatter.Bold(member.DisplayName)} with message: {Formatter.BlockCode(msg)}", important : false); }
public SettingsModule(DiscordContext context, DiscordDmChannel dm, CommandContext ctx, long userId) { _context = context; _dm = dm; _userId = userId; _ctx = ctx; }
private async Task EstablishTriviaMasterDm() { _triviaMasterDmChannel = await _client.CreateDmAsync(_triviaMaster); await _triviaMasterDmChannel.SendMessageAsync( $"You have been established as the Trivia Master for a Trivia {GetGameName()}"); }
static async Task DeleteDmsMessages(DiscordDmChannel channel) { Console.WriteLine($"Deleting messages...", Color.Green); ulong?first = null; int cnt = 0; do { var messages = await channel.GetMessagesAsync(100, first); if (messages.Count == 0) { break; } var ownMessages = messages.Where(k => k.Author.Id == client.CurrentUser.Id); cnt += ownMessages.Count(); first = messages.Last().Id; foreach (var message in ownMessages) { await channel.DeleteMessageAsync(message); } }while (first.HasValue); Console.WriteLine($"Deleted {cnt} messages!", Color.Green); }
public static async Task PresenceUpdated(PresenceUpdateEventArgs e, DiscordClient client, Dictionary <DiscordMember, DateTime> gameStartedDictionary) { if (Komobase.IsSubscribed(e.Member.Username)) { //if just started playing if (e.Game != null && e.Game.Name != null && !gameStartedDictionary.ContainsKey(e.Member) && (e.PresenceBefore.Game == null || e.PresenceBefore.Game.Name == string.Empty)) { gameStartedDictionary.Add(e.Member, DateTime.Now); } //if ended else if (e.Game == null || e.Game.Name == null || e.Game.Name == string.Empty) { if (gameStartedDictionary.ContainsKey(e.Member)) { DiscordDmChannel dm = await client.CreateDmAsync(e.Member); await client.SendMessageAsync(dm, "No! Ennyit függtél most: " + GetTimeLapsedString(DateTime.Now, gameStartedDictionary[e.Member]), false, null); gameStartedDictionary.Remove(e.Member); } } } }
public async Task SendErrorReportAsync(CommandContext ctx, [RemainingText, Description("Issue text.")] string issue) { if (string.IsNullOrWhiteSpace(issue)) { throw new InvalidCommandUsageException("Text missing."); } if (await ctx.WaitForBoolReplyAsync("Are you okay with your user and guild info being sent for further inspection?")) { ctx.Client.DebugLogger.LogMessage(LogLevel.Info, "TheGodfather", $"Report from {ctx.User.Username} ({ctx.User.Id}): {issue}", DateTime.Now); DiscordDmChannel dm = await ctx.Client.CreateDmChannelAsync(ctx.Client.CurrentApplication.Owners.First().Id); if (dm is null) { throw new CommandFailedException("Owner has disabled DMs."); } var emb = new DiscordEmbedBuilder { Title = "Issue", Description = issue }; emb.WithAuthor(ctx.User.ToString(), iconUrl: ctx.User.AvatarUrl ?? ctx.User.DefaultAvatarUrl); emb.AddField("Guild", $"{ctx.Guild.ToString()} owned by {ctx.Guild.Owner.ToString()}"); await dm.SendMessageAsync("A new issue has been reported!", embed : emb.Build()); await this.InformAsync(ctx, "Your issue has been reported.", important : false); } }
public Villager(DiscordDmChannel discordDmChannel, DiscordUser discordUser, DiscordEmoji discordEmoji) { DiscordDmChannel = discordDmChannel; DiscordUser = discordUser; DiscordEmoji = discordEmoji; Name = "Villager"; }
public async Task CreateItem(CommandContext ctx) { TextStep itemDescriptionStep = new TextStep("Describe the item.", null); TextStep itemNameStep = new TextStep("What will the item be called?", itemDescriptionStep); Item item = new Item(); itemNameStep.OnValidResult += (result) => item.Name = result; itemDescriptionStep.OnValidResult += (result) => item.Description = result; DiscordDmChannel userChannel = await ctx.Member.CreateDmChannelAsync().ConfigureAwait(false); DialogueHandler inputDialogueHandler = new DialogueHandler(ctx.Client, userChannel, ctx.User, itemNameStep); bool succeeded = await inputDialogueHandler.ProcessDialogue().ConfigureAwait(false); if (!succeeded) { return; } await _itemService.CreateNewItemAsync(item).ConfigureAwait(false); await ctx.Channel.SendMessageAsync($"Item {item.Name} successfully created.").ConfigureAwait(false); }
public async Task <EventHandlerResult> Handle(MessageReactionAddEventArgs eventArgs) { // https://discordapp.com/channels/366970031445377024/507515506073403402/686745124885364770 if (!(eventArgs.Message.Id == _config.VerificationMessageId && eventArgs.Message.ChannelId == _config.VerificationChannelId)) { return(EventHandlerResult.Continue); } if (!eventArgs.Emoji.Name.Equals(_config.VerificationEmojiName)) { return(EventHandlerResult.Continue); } DiscordUser user = eventArgs.User; DiscordDmChannel channel = await eventArgs.Guild.Members[user.Id].CreateDmChannelAsync(); string link = _urlProvider.GetAuthLink(user.Id, RolesPool.Auth); if (await _authorizationService.IsUserVerified(user.Id)) { await channel.SendMessageAsync( $"Ahoj, už jsi ověřený.\nPro aktualizaci rolí dle UserMap klikni na odkaz: {link}"); } else { await channel.SendMessageAsync( $"Ahoj, pro ověření a přidělení rolí dle UserMap klikni na odkaz: {link}"); } return(EventHandlerResult.Stop); }
public async Task SendAsync(CommandContext ctx, [Description("u/c (for user or channel.)")] string desc, [Description("User/Channel ID.")] ulong xid, [RemainingText, Description("Message.")] string message) { if (string.IsNullOrWhiteSpace(message)) { throw new InvalidCommandUsageException(); } if (desc == "u") { DiscordDmChannel dm = await ctx.Client.CreateDmChannelAsync(xid); if (dm == null) { throw new CommandFailedException("I can't talk to that user..."); } await dm.SendMessageAsync(message); } else if (desc == "c") { DiscordChannel channel = await ctx.Client.GetChannelAsync(xid); await channel.SendMessageAsync(message); } else { throw new InvalidCommandUsageException("Descriptor can only be 'u' or 'c'."); } await this.InformAsync(ctx, $"Successfully sent the given message!", important : false); }
public async Task DisplayData(DiscordDmChannel d, bool Roles) { DiscordEmbedBuilder embed = new DiscordEmbedBuilder() { Color = DiscordColor.Blue, Title = "Secret Villain™" } .WithFooter("Heroes & Villains"); foreach (UserObject user in Players) { string statusString = user.Status == 0 ? "Alive" : user.Status == 1 ? "Dead" : "ERROR, Please report this to Jcryer."; string playerNumString = user.PlayerNum == -1 ? "N/A" : user.Status >= 0 ? user.PlayerNum.ToString() : "ERROR, Please report this to Jcryer."; string roleType = user.Role == 1 ? "Villain" : user.Role == 2 ? "Medic" : user.Role == 3 ? "Spy" : user.Role == 4 ? "Joker" : user.Role == 5 ? "Hero" : "ERROR, Please report this to Jcryer."; if (Roles) { embed.AddField(user.Username, "Role: " + roleType); } else { embed.AddField(user.Username, "Player number: " + playerNumString + Environment.NewLine + "Status: " + statusString); } } await d.SendMessageAsync("", embed : embed); }
public static async Task <DiscordDmChannel> SendBanDMAsync(this DiscordDmChannel channel, string title, string description) { var e = new DiscordEmbedBuilder() .WithTitle(title) .WithColor(DiscordColor.Red) .WithDescription(description + " [here](https://forms.gle/PyxFAAKQ5W4GA8F5A)"); var message = await channel.SendMessageAsync(embed : e.Build()); return(channel); }
public static async Task <DiscordDmChannel> SendDMAsync(this DiscordDmChannel channel, string title, string description) { var e = new DiscordEmbedBuilder() .WithTitle(title) .WithColor(DiscordColor.Red) .WithDescription(description); var message = await channel.SendMessageAsync(embed : e.Build()); return(channel); }
public async Task Gibinvite(CommandContext ctx, int max_uses = 1, int age = 0) { DiscordChannel channel = await ctx.Client.GetChannelAsync(230004550973521932); DiscordInvite inv = await channel.CreateInviteAsync(age, max_uses, false, true, $"gibinvite command used in {ctx.Channel.Id}"); DiscordDmChannel chan = await ctx.Member.CreateDmChannelAsync(); await chan.SendMessageAsync($"Here's the invite you asked for: https://discord.gg/{inv.Code}"); await ctx.Channel.SendMessageAsync($"{Program.cfgjson.Emoji.Check} I've DMed you an invite to **Erisa's Corner** with `{max_uses}` use(s) and an age of `{age}`!"); }
protected override void OnNavigatedTo(NavigationEventArgs e) { if (e.Parameter is DiscordDmChannel channel) { _currentChannel = channel; dmsList.SelectedItem = channel; } else { _currentChannel = null; dmsList.SelectedIndex = -1; } }
public static async Task LogPrivate(DiscordDmChannel channel, string functionName, string description, string message, DiscordColor color) { DiscordEmbedBuilder builder = new DiscordEmbedBuilder(); builder.WithTitle("Changelog"); builder.WithThumbnailUrl("https://media.discordapp.net/attachments/496417444613586984/496671867109769216/logthumbnail.png"); builder.WithDescription("Info"); builder.AddField(name: "Command", value: $"{functionName}", inline: true); builder.AddField(name: "Description", value: $"{description}", inline: true); builder.AddField(name: "Message", value: $"{message}"); builder.WithFooter("Copyright 2018 Lala Sabathil"); await channel.SendMessageAsync(content : null, tts : false, embed : builder.Build()); }
public async Task ExecuteGroupAsync(CommandContext ctx) { if (this.Shared.IsEventRunningInChannel(ctx.Channel.Id)) { throw new CommandFailedException("Another event is already running in the current channel!"); } DiscordDmChannel dm = await ctx.Client.CreateDmChannelAsync(ctx.User.Id); if (dm == null) { throw new CommandFailedException("Please enable direct messages, so I can ask you about the word to guess."); } await dm.EmbedAsync("What is the secret word?", StaticDiscordEmoji.Question, this.ModuleColor); await this.InformAsync(ctx, StaticDiscordEmoji.Question, $"{ctx.User.Mention}, check your DM. When you give me the word, the game will start."); MessageContext mctx = await ctx.Client.GetInteractivity().WaitForMessageAsync( xm => xm.Channel == dm && xm.Author.Id == ctx.User.Id, TimeSpan.FromMinutes(1) ); if (mctx == null) { await this.InformFailureAsync(ctx, "I didn't get the word, so I will abort the game."); return; } else { await dm.EmbedAsync($"Alright! The word is: {Formatter.Bold(mctx.Message.Content)}", StaticDiscordEmoji.Information, this.ModuleColor); } var hangman = new HangmanGame(ctx.Client.GetInteractivity(), ctx.Channel, mctx.Message.Content, mctx.User); this.Shared.RegisterEventInChannel(hangman, ctx.Channel.Id); try { await hangman.RunAsync(); if (hangman.Winner != null) { await this.Database.UpdateUserStatsAsync(hangman.Winner.Id, GameStatsType.HangmansWon); } } finally { this.Shared.UnregisterEventInChannel(ctx.Channel.Id); } }
public async Task JoinVillageCommand(CommandContext ctx) { //Vérification de base character + guild if (!dep.Entities.Characters.IsPresent(ctx.User.Id) || !dep.Entities.Guilds.IsPresent(ctx.Guild.Id)) { return; } Character character = dep.Entities.Characters.GetCharacterByDiscordId(ctx.User.Id); Case currentCase = dep.Entities.Map.GetCase(character.Location); //1 check existence village + appartenance village if (character.VillageName != null || currentCase.VillageId == ulong.MinValue) { DiscordEmbedBuilder embed = dep.Embed.CreateBasicEmbed(ctx.User, dep.Dialog.GetString("errorCantJoinVillage")); await ctx.RespondAsync(embed : embed); return; } //2 sinon ajout liste attente village // + prévenir roi ? Village village = dep.Entities.Villages.GetVillageById(currentCase.VillageId); if (!village.WaitingList.Contains(character.Id)) { village.WaitingList.Add(character.Id); } DiscordMember king = await ctx.Guild.GetMemberAsync(village.KingId); if (king != null) { DiscordDmChannel dm = await king.CreateDmChannelAsync(); DiscordEmbedBuilder embed = dep.Embed.CreateBasicEmbed(king, dep.Dialog.GetString("joinVillageMPKing")); await dm.SendMessageAsync(embed : embed); DiscordEmbedBuilder embedConfirm = dep.Embed.CreateBasicEmbed(king, dep.Dialog.GetString("joinvillageConfirmWaiting")); await ctx.RespondAsync(embed : embedConfirm); } else { DiscordEmbedBuilder embed = dep.Embed.CreateBasicEmbed(ctx.User, dep.Dialog.GetString("error")); await ctx.RespondAsync(embed : embed); } }
private static async Task UpdateOwnerDm() { if (_ownerDm == null) { DiscordMember ownerMember = Client.Guilds.Values.SelectMany(g => g.Members).FirstOrDefault(m => m.Id == Client.CurrentApplication.Owner.Id); if (ownerMember != null) { _appLogArea.WriteLine($"Owner member found! {ownerMember}"); _ownerDm = await ownerMember.CreateDmChannelAsync(); } else { _appLogArea.WriteLine("Unable to find owner member, Exception information will be unavailable."); } } }
public async Task Place(CommandContext ctx, string cards) { if (!ctx.Channel.IsPrivate) { await ctx.Channel.SendMessageAsync(null, false, await DiscordEmbed.ErrorMessage("Please play the game in your DMs!")); return; } DiscordDmChannel dm = (DiscordDmChannel)ctx.Channel; var player = await GetPlayer(dm.Recipients[0].Username); foreach (string card in cards.Split()) { if (card.Length >= 4) { await ctx.Member.SendMessageAsync(null, false, await DiscordEmbed.ErrorMessage("Incorrect card format! Try entering the value and/or suit of one of your cards! Ex: 6 or 6D")); return; } } List <Card> chosen = await GetCards(ctx, player, cards); if (await IsPlaceable(chosen, game.pile[0])) { chosen.Reverse(); game.pile.InsertRange(0, chosen); foreach (Card c in chosen) { player.hand.Remove(c); } await Display.HandImg(player.hand, player.user.DisplayName); await Display.TopPileImg(game.pile); await ctx.Channel.SendMessageAsync(null, false, await DiscordEmbed.DisplayCards(await client.GetChannelAsync(721038967155458059), player)); } else { await ctx.Channel.SendMessageAsync(null, false, await DiscordEmbed.ErrorMessage("Cards cannot be placed!")); } return; }
public async Task AuthorizeCommand(CommandContext ctx) { DiscordMessage message = ctx.Message; DiscordUser user = message.Author; DiscordDmChannel channel = await message.Channel.Guild.Members[user.Id].CreateDmChannelAsync(); string link = _urlProvider.GetAuthLink(user.Id, RolesPool.Auth); if (await _authorizationService.IsUserVerified(user.Id)) { await channel.SendMessageAsync( $"You are already authorized.\nTo update roles follow this link: {link}"); } else { await channel.SendMessageAsync($"Hi, authorize by following this link: {link}"); } }
private void UpdateMessage(DiscordMessage message, TransportUser author, DiscordGuild guild, TransportMember member) { if (author != null) { var usr = new DiscordUser(author) { Discord = this }; if (member != null) { member.User = author; } message.Author = this.UpdateUser(usr, guild?.Id, guild, member); } var channel = this.InternalGetCachedChannel(message.ChannelId); if (channel != null) { return; } if (!message.GuildId.HasValue) { channel = new DiscordDmChannel { Id = message.ChannelId, Discord = this, Type = ChannelType.Private }; } else { channel = new DiscordChannel { Id = message.ChannelId, Discord = this }; } message.Channel = channel; }
public async Task ExecuteGroupAsync(CommandContext ctx) { DiscordEmbedBuilder builder = new DiscordEmbedBuilder() { Color = DiscordColor.Orange, Title = "Wolfy help", Description = "Hi, I'm Wolfy! <:awoo:254007902510120961>" }; builder.WithAuthor(ctx.Client.CurrentUser.Username, null, ctx.Client.CurrentUser.AvatarUrl); StringBuilder triggerBuilder = new StringBuilder(); triggerBuilder.AppendLine("There isn't any official help for my triggers. Offer me a <:wolfybone:259416003534913537>, or tell me to do a flip? Maybe regulars know a few more things I can do."); builder.AddField("Triggers", triggerBuilder.ToString()); builder.AddField("Commands", "`!awoo`: Posts an awoo image.\r\n`!winnie`: Posts a winnie image.\r\n`!help`: Displays this message."); DiscordDmChannel chan = await ctx.Client.CreateDmAsync(ctx.Message.Author); await chan.SendMessageAsync(embed : builder); }
internal DiscordChannel InternalGetCachedChannel(ulong channelId) { DiscordDmChannel foundDmChannel = default; if (this._privateChannels?.TryGetValue(channelId, out foundDmChannel) == true) { return(foundDmChannel); } foreach (var guild in this.Guilds.Values) { if (guild.Channels.TryGetValue(channelId, out var foundChannel)) { return(foundChannel); } } return(null); }
public async Task JoinAsync(CommandContext ctx) { if (!(this.Shared.GetEventInChannel(ctx.Channel.Id) is HoldemGame game)) { throw new CommandFailedException("There are no Texas Hold'Em games running in this channel."); } if (game.Started) { throw new CommandFailedException("Texas Hold'Em game has already started, you can't join it."); } if (game.Participants.Count >= 7) { throw new CommandFailedException("Texas Hold'Em slots are full (max 7 participants), kthxbye."); } if (game.IsParticipating(ctx.User)) { throw new CommandFailedException("You are already participating in the Texas Hold'Em game!"); } DiscordMessage handle; try { DiscordDmChannel dm = await ctx.Client.CreateDmChannelAsync(ctx.User.Id); handle = await dm.SendMessageAsync("Alright, waiting for Hold'Em game to start! Once the game starts, return here to see your hand!"); } catch { throw new CommandFailedException("I can't send you a message! Please enable DMs from me so I can send you the cards."); } using (DatabaseContext db = this.Database.CreateContext()) { if (!await db.TryDecreaseBankAccountAsync(ctx.User.Id, ctx.Guild.Id, game.MoneyNeeded)) { throw new CommandFailedException($"You do not have enough {this.Shared.GetGuildConfig(ctx.Guild.Id).Currency ?? "credits"}! Use command {Formatter.InlineCode("bank")} to check your account status."); } await db.SaveChangesAsync(); } game.AddParticipant(ctx.User, handle); await this.InformAsync(ctx, StaticDiscordEmoji.CardSuits[0], $"{ctx.User.Mention} joined the Hold'Em game."); }
public static async Task PresenceUpdated(PresenceUpdateEventArgs e, DiscordClient client) { if (!e.Member.IsBot) { try { using (KomoBaseAccess kba = new KomoBaseAccess()) { bool subStatus = kba.SubStatus(e.Member.Username); bool isStopped = (e.Game == null || e.Game.Name == null || e.Game.Name == string.Empty) && gameStartedDictionary.ContainsKey(e.Member); int points = 0; string msg = string.Empty; //add points if (isStopped) { msg = GetTimeLapsedString(DateTime.Now, gameStartedDictionary[e.Member], out points); kba.AddPoints(e.Member.Username, points); } //if just started playing if (e.Game != null && e.Game.Name != null && !gameStartedDictionary.ContainsKey(e.Member) && (e.PresenceBefore.Game == null || e.PresenceBefore.Game.Name == string.Empty)) { gameStartedDictionary.Add(e.Member, DateTime.Now); } //if ended else if (isStopped) { gameStartedDictionary.Remove(e.Member); } if (subStatus == true && isStopped) { DiscordDmChannel dm = await client.CreateDmAsync(e.Member); await client.SendMessageAsync(dm, "No! Ennyit függtél most: " + msg, false, null); } } } catch (Exception ex) { logger.Error(DateTime.UtcNow.ToString() + ": " + ex.Message); } } }
public Func <string, Task <DiscordMessage> > RespondTTS(bool delete, TimeSpan timeout) { return(async(content) => { DiscordMessage response; if (_directMessage) { DiscordDmChannel dm = await _context.Member.CreateDmChannelAsync(); response = await dm.SendMessageAsync(content, true); } else { response = await _message.RespondAsync(content, true); await DeleteMessages(response, delete, timeout); } return response; }); }
public async Task CreateAsync(CommandContext ctx, [Description("Channel to list webhooks for.")] DiscordChannel channel, [Description("Name.")] string name, [Description("Avatar URL.")] Uri avatarUrl = null, [RemainingText, Description("Reason.")] string reason = null) { DiscordWebhook wh; if (avatarUrl is null) { wh = await channel.CreateWebhookAsync(name, reason : ctx.BuildInvocationDetailsString(reason)); } else { try { using (Stream stream = await _http.GetStreamAsync(avatarUrl)) using (var ms = new MemoryStream()) { await stream.CopyToAsync(ms); ms.Seek(0, SeekOrigin.Begin); wh = await channel.CreateWebhookAsync(name, ms, reason : ctx.BuildInvocationDetailsString(reason)); } } catch (WebException e) { throw new CommandFailedException("Failed to fetch the image!", e); } } await this.InformAsync(ctx, "Created a new webhook! Sending you the token in private...", important : false); try { DiscordDmChannel dm = await ctx.Client.CreateDmChannelAsync(ctx.User.Id); if (dm is null) { throw new CommandFailedException("I failed to send you the token in private."); } await dm.SendMessageAsync($"Token for webhook {Formatter.Bold(wh.Name)} in {Formatter.Bold(ctx.Guild.ToString())}, {Formatter.Bold(channel.ToString())}: {Formatter.BlockCode(wh.Token)}\nWebhook URL: {wh.BuildUrlString()}"); } catch { // Failed to create DM or insufficient perms to send } }