private async Task ListenForQuoteApproval(Cacheable <IUserMessage, ulong> arg1, ISocketMessageChannel arg2, SocketReaction arg3) { //Emote confirmEmote = Emote.Parse("<:qbotDENY:858130936376590407>"); //Emote declineEmote = Emote.Parse("<:qbotAPPROVE:858130946985689088>"); IMessage msg = await arg2.GetMessageAsync(arg1.Id); //This works. This gets the appropriate message. if (msg != null) { try { foreach (var item in msg.Reactions) { if (item.Key.Name == "qbotAPPROVE" && item.Value.ReactionCount == 2) { //Get the quote ID from the string. string[] QuoteData = msg.Content.Split('\n'); string QuoteID = QuoteData[2].Split(' ')[2]; //Pulls the quote ID from the 2nd line. Quote targetQuote = QuotesPendingApproval.Find(x => x.QuoteID == Convert.ToInt32(QuoteID)); //Add the quote to the list based on the last ID of the actual quote library. targetQuote.QuoteID = MasterQuoteList[MasterQuoteList.Count - 1].QuoteID + 1; await ReplyAsync($"Yes! A new Quote ({QuoteID}) is born!\nID: {targetQuote.QuoteID}\n\n{targetQuote.QuoteContents}"); await arg2.DeleteMessageAsync(msg); //Delete the message in the Colonel Quote Audit Channel. You already have the ID. //Time to add the quote. QuotesPendingApproval.Remove(targetQuote); MasterQuoteList.Add(targetQuote); WriteQuoteList(); discordclient.ReactionAdded -= ListenForQuoteApproval; } else if (item.Key.Name == "qbotDENY" && item.Value.ReactionCount == 2) { string[] QuoteData = msg.Content.Split('\n'); string QuoteID = QuoteData[2].Split(' ')[2]; //Pulls the quote ID from the 2nd line. //await ReplyAsync($"Quote {QuoteID} was denied by a moderator (Method 2)"); await arg2.DeleteMessageAsync(msg); //Delete the message in the Colonel Quote Audit Channel. You already have the ID. discordclient.ReactionAdded -= ListenForQuoteApproval; } } } catch (Exception) { discordclient.ReactionAdded -= ListenForQuoteApproval; } } }
private static async Task OnPlayReactionAsync(PaginatorSenderService sender, Paginator <object> paginator, Cacheable <IUserMessage, ulong> cache, ISocketMessageChannel chan, SocketReaction reaction) { if (!(chan is IGuildChannel) || reaction.User.Value == null) { return; } IGuildUser guser = (IGuildUser)reaction.User.Value; if (guser.VoiceChannel == null) { return; } ITextChannel textChan = (ITextChannel)chan; IMusicPlayerService music = sender.ServiceManager.GetService <IMusicPlayerService>("Music"); switch (paginator.CurrentValue) { case ILavaTrack track: await music.AddTrackAsync(guser.VoiceChannel, textChan, track); await chan.DeleteMessageAsync(paginator.Message); break; case string url: if (string.IsNullOrWhiteSpace(url)) { return; } SearchResult result = await music.LavaRestClient.SearchTracksAsync(url); List <ILavaTrack> tracks = result.Tracks.ToList(); if (tracks.Count > 0) { ILavaTrack tr = tracks[0]; await music.AddTrackAsync(guser.VoiceChannel, textChan, tr); await chan.DeleteMessageAsync(paginator.Message); } else { await sender.MessageSender.SendWarningAsync(chan, "music player", $"Could not add the following Url to the queue\n{url}"); } break; } }
public static async Task Run(SocketSlashCommand command, DiscordSocketClient client, Dictionary <string, SocketSlashCommandDataOption> options, ISocketMessageChannel recruitingChannel, List <IMessage> messages, List <Team> teams) { var guildUser = (SocketGuildUser)options["username"].Value; var discordUser = guildUser.Nickname ?? guildUser.Username; // Player not exist? -> respond with error (var oldTeam, var player) = Team.FindPlayer(teams, discordUser); if (player == null) { await command.RespondAsync($"User {discordUser} does not exist in the recruiting table", ephemeral : true); return; } // If player was captain of old team remove that teams captain if (oldTeam.Captain?.DiscordUser == player.DiscordUser) { oldTeam.Captain = null; } // Move Player oldTeam.Players.Remove(player); // Update old team message if (oldTeam.Players.Count > 0) { await recruitingChannel.ModifyMessageAsync(oldTeam.MsgId, (message) => message.Content = oldTeam.ToMessage()); } else { await recruitingChannel.DeleteMessageAsync(oldTeam.MsgId); } await command.RespondAsync($"You have removed user {discordUser} from {oldTeam.Name}", ephemeral : true); }
public async Task <Dictionary <ulong, VoteEmbed> > AddVote(SocketReaction reaction, ISocketMessageChannel messageChannel) { if (reaction.Emote.Name != "\u2611") { return(TrackingVote); } try { await Channel.GetUserAsync(reaction.UserId); } catch (Exception) { return(TrackingVote); } Votes++; var chnl = Channel as SocketGuildChannel; int users = chnl.Users.Count - 1; if (Votes >= (users / 2.0)) { await messageChannel.SendMessageAsync("", false, await Skip()); voteMutex.WaitOne(); TrackingVote.Remove(reaction.MessageId); voteMutex.ReleaseMutex(); await messageChannel.DeleteMessageAsync(reaction.MessageId); } return(TrackingVote); }
public static async Task Run(SocketSlashCommand command, DiscordSocketClient client, StorageClient storageClient, Dictionary <string, SocketSlashCommandDataOption> options, Guild guild, ISocketMessageChannel recruitingChannel, List <Team> teams) { var guildUser = (SocketGuildUser)options["username"].Value; var discordUser = guildUser.Nickname ?? guildUser.Username; // Player not exist? -> respond with error (var oldTeam, var player) = Team.FindPlayer(teams, discordUser); if (player == null) { await command.FollowupAsync($"User {discordUser} does not exist in the recruiting table", ephemeral : true); return; } oldTeam.RemovePlayer(player); // Update old team message if (oldTeam.Players.Count > 0) { await recruitingChannel.ModifyMessageAsync(oldTeam.MsgId, (message) => message.Content = oldTeam.ToMessage()); await storageClient.SaveTableRow(Team.TableName, oldTeam.Name, guild.RowKey, oldTeam); } else { await recruitingChannel.DeleteMessageAsync(oldTeam.MsgId); await storageClient.DeleteTableRow(Team.TableName, oldTeam.Name, guild.RowKey); } await command.FollowupAsync($"You have removed user {discordUser} from {oldTeam.Name}", ephemeral : true); }
private async Task OnReactionRemoved(Cacheable <IUserMessage, ulong> cache, ISocketMessageChannel channel, SocketReaction reaction) { if (reaction.User.Value.IsBot) { return; } var selectedTrack = selectEmbed.CheckSelection(reaction.User.Value as SocketGuildUser, reaction); if (selectedTrack != null) { var embed = await PlayAsync(selectedTrack, (channel as SocketGuildChannel).Guild, reaction.User.Value as SocketGuildUser); await channel.SendMessageAsync("", false, embed); ControlPanelAsync(channel); selectEmbed.RemoveSelection(reaction.MessageId); await channel.DeleteMessageAsync(reaction.MessageId); } if (_TrackingControlPanels.ContainsKey(reaction.MessageId)) { var controlPanel = _TrackingControlPanels[reaction.MessageId].Value; AdminUsers = await controlPanel.CheckCommand(channel, reaction, _TrackingControlPanels[reaction.MessageId].Key, _lavaNode, AdminUsers); } if (VoteEmbed.TrackingVote.ContainsKey(reaction.MessageId)) { await VoteEmbed.TrackingVote[reaction.MessageId].RemoveVote(reaction); } }
private async Task ReactionAdded(Cacheable <IUserMessage, ulong> ch, ISocketMessageChannel chanel, SocketReaction reaction) { IUserMessage msg = await ch.GetOrDownloadAsync(); if (msg == null) { return; } if (QuoteModule._trackedQuoteList.Keys.Contains(msg.Id) && !reaction.User.Value.IsBot) { if (reaction.Emote.Name == "✅") { await chanel.DeleteMessageAsync(msg.Id); QuoteModule._trackedQuoteList.Remove(msg.Id); } else { //add to file File.AppendAllLines(fileName, new string[] { QuoteModule._trackedQuoteList[msg.Id].Id.ToString() }); await chanel.DeleteMessageAsync(msg.Id); QuoteModule._trackedQuoteList.Remove(msg.Id); } } if (reaction.Emote.Name == "💬" && !msg.Author.IsBot) { try { await QuoteModule.BotAddQuote(_services.GetService <IQouteRepository>(), _services.GetService <IScoreRepository>(), _services.GetService <IUserRepository>(), chanel, msg.Content, msg.Id, reaction.User.GetValueOrDefault(null) as IGuildUser , msg.Author as IGuildUser, msg.Timestamp.DateTime); } catch (Exception e) { if (e.GetType().Equals(typeof(QuotingYourselfException))) { await msg.Channel.SendMessageAsync("A bit narcissistic to quote yourself, no?"); } else { await EmbedBuilderFunctions.UnhandledException(e.Message, msg.Channel as ISocketMessageChannel); } } } }
private async Task OnMessageDelete(Cacheable <IMessage, ulong> cacheable, ISocketMessageChannel channel) { var messageId = _messageService.GetResponseFromCommandLogEntry(cacheable.Id); if (messageId != 0) { channel.DeleteMessageAsync(messageId); } }
public async Task <Dictionary <ulong, ulong> > CheckCommand(ISocketMessageChannel channel, SocketReaction reaction, RestUserMessage message, LavaNode lavaNode, Dictionary <ulong, ulong> Providers)//переделать на симофор { var guild = (channel as SocketGuildChannel).Guild; if (reaction.User.Value.Id != Provider.Id) { return(Providers); } switch (reaction.Emote.Name) { case ("🔺"): await IncreaseVolumeAsync(); break; case ("🔻"): await DecreaseVolumeAsync(); break; case ("\u23EF"): await PauseOrResumeAsync(); break; case ("\u23ED"): await AddPositionAsync(); break; case ("\u23EE"): await RemovePositionAsync(); break; case ("🔲"): await SkipAsync(); break; case ("\u274C"): Providers.Remove(reaction.UserId); await channel.DeleteMessageAsync(reaction.MessageId); await lavaNode.LeaveAsync(guild.CurrentUser.VoiceChannel); break; } await ModifyMessage(message); return(Providers); }
private async Task Client_MessageDeletedAsync(Cacheable <IMessage, ulong> messageCacheable, ISocketMessageChannel channel) { var eventForMessage = DbContext.Events.AsQueryable().Where(e => e.CommandMessageId == messageCacheable.Id).FirstOrDefault(); if (eventForMessage != null) { var messageForEvent = await channel.GetMessageAsync(eventForMessage.EventMessageId); await channel.DeleteMessageAsync(messageForEvent); DbContext.Events.Remove(eventForMessage); DbContext.SaveChanges(); } }
private async Task Client_MessageDeleted(Discord.Cacheable <Discord.IMessage, ulong> arg1, ISocketMessageChannel arg2) { // if the original message was successful and is deleted, delete the related messages if (CommandMessageResults.ContainsKey(arg1.Id)) { var messageId = CommandMessageResults[arg1.Id]; try { // delete the result of the original command message await arg2.DeleteMessageAsync(messageId); } catch (HttpException) { } } }
public static async Task <ulong> EmbedWriter(ISocketMessageChannel chan, IUser user, string title, string data, bool pinned = false, bool image = true, bool direct = false, int time = 30000) { var embed = new EmbedBuilder(); embed.WithTitle(title); embed.WithUrl("https://github.com/Haceo/SkynetBot"); embed.WithDescription(data); embed.WithColor(new Color(100, 65, 165)); embed.WithFooter($"Author: {user} - {user.Id}"); if (image) { embed.WithThumbnailUrl(user.GetAvatarUrl()); } var embedded = embed.Build(); if (time == -1 && !direct) { var msg = await chan.SendMessageAsync("", false, embedded); if (pinned) { await msg.PinAsync(); } return(msg.Id); } else { if (!direct) { var msg = await chan.SendMessageAsync("", false, embedded); await Task.Delay(time); await chan.DeleteMessageAsync(msg); return(msg.Id); } else { var msg = await user.SendMessageAsync("", false, embedded); return(msg.Id); } } }
public static async Task Run(SocketSlashCommand command, DiscordSocketClient client, Dictionary <string, SocketSlashCommandDataOption> options, ISocketMessageChannel recruitingChannel, List <IMessage> messages, List <Team> teams) { var teamName = options["team"].Value.ToString(); // Player not exist? -> respond with error var team = Team.FindTeam(teams, teamName); if (team == null) { await command.RespondAsync($"Team {teamName} does not exist in the recruiting table", ephemeral : true); return; } // Remove old team message await recruitingChannel.DeleteMessageAsync(team.MsgId); await command.RespondAsync($"You have removed team {teamName}", ephemeral : true); }
private async Task ReactionAdded(Cacheable <IUserMessage, ulong> message, ISocketMessageChannel channel, SocketReaction reaction) { try { if (!this.messageEventLookup.ContainsKey(message.Id.ToString())) { return; } // don't mark yourself as attending! if (reaction.UserId == Program.DiscordClient.CurrentUser.Id) { return; } string eventId = this.messageEventLookup[message.Id.ToString()]; Event? evt = await EventsDatabase.Load(eventId); if (evt is null) { // this event was deleted while the notification was up. // we need to detect this case in the 'Update' loop to clear old notifications. // but for now, we'll handle it when someone reacts. this.messageEventLookup.Remove(message.Id.ToString()); await channel.DeleteMessageAsync(message.Value); return; } if (evt.Notify == null) { return; } Event.Instance.Attendee?attendee = evt.GetAttendee(reaction.UserId); if (attendee == null) { attendee = new Event.Instance.Attendee(); attendee.UserId = reaction.UserId.ToString(); evt.Notify.Attendees.Add(attendee); await EventsDatabase.Save(evt); } if (Emotes.IsEmote(reaction.Emote, Emotes.Bell)) { ////ReminderService.SetReminder(evt, attendee); evt.ToggleAttendeeReminder(reaction.UserId); await EventsDatabase.Save(evt); } else { (string display, int index) = GetStatus(reaction.Emote); if (index < 0) { return; } evt.SetAttendeeStatus(reaction.UserId, index); await EventsDatabase.Save(evt); } await evt.Notify.Post(evt); RestUserMessage userMessage = (RestUserMessage)await channel.GetMessageAsync(message.Id); SocketUser user = Program.DiscordClient.GetUser(reaction.UserId); await userMessage.RemoveReactionAsync(reaction.Emote, user); } catch (Exception ex) { Log.Write(ex); } }
public static async Task Run(SocketSlashCommand command, DiscordSocketClient client, StorageClient storageClient, Dictionary <string, SocketSlashCommandDataOption> options, Guild guild, ISocketMessageChannel recruitingChannel, List <Team> teams) { var guildUser = (SocketGuildUser)options["username"].Value; var discordUser = guildUser.Nickname ?? guildUser.Username; var teamName = options["team"].Value.ToString(); var captain = options.ContainsKey("captain") && (bool)options["captain"].Value; // Player not exist? -> respond with error (var oldTeam, var player) = Team.FindPlayer(teams, discordUser); if (player == null) { await command.FollowupAsync($"User {discordUser} does not exist in the recruiting table", ephemeral : true); return; } oldTeam.RemovePlayer(player); var newTeam = Team.AddPlayer(teams, teamName, player, captain); bool isNewTeam = newTeam.MsgId == 0; // Update old team message if (oldTeam.Players.Count > 0) { await recruitingChannel.ModifyMessageAsync(oldTeam.MsgId, (message) => message.Content = oldTeam.ToMessage()); } else { await recruitingChannel.DeleteMessageAsync(oldTeam.MsgId); } // Update new team message if (newTeam.MsgId == 0) { newTeam.MsgId = (await recruitingChannel.SendMessageAsync(newTeam.ToMessage())).Id; } else { await recruitingChannel.ModifyMessageAsync(newTeam.MsgId, (message) => message.Content = newTeam.ToMessage()); } var transactions = new List <(string, TableTransactionActionType, Team, ETag)>(); if (oldTeam.Players.Count > 0) { transactions.Add((oldTeam.Name, TableTransactionActionType.UpdateMerge, oldTeam, oldTeam.etag)); } else { transactions.Add((oldTeam.Name, TableTransactionActionType.Delete, null, oldTeam.etag)); } if (!string.Equals(newTeam.Name, oldTeam.Name, StringComparison.OrdinalIgnoreCase)) { transactions.Add((newTeam.Name, isNewTeam ? TableTransactionActionType.UpsertMerge : TableTransactionActionType.UpdateMerge, newTeam, newTeam.etag)); } // if the transaction fails it should retry, and then the message will be updated to reflect the actual value in storage. await storageClient.ExecuteTransaction(Team.TableName, transactions, guild.RowKey); await command.FollowupAsync($"You have moved user {discordUser} from {oldTeam.Name} -> {newTeam.Name}", ephemeral : true); }
public static async Task Run(SocketSlashCommand command, DiscordSocketClient client, Dictionary <string, SocketSlashCommandDataOption> options, ISocketMessageChannel recruitingChannel, List <IMessage> messages, List <Team> teams) { var guildUser = (SocketGuildUser)options["username"].Value; var discordUser = guildUser.Nickname ?? guildUser.Username; // Player not exist? -> respond with error (var oldTeam, var player) = Team.FindPlayer(teams, discordUser); if (player == null) { await command.RespondAsync($"User {discordUser} does not exist in the recruiting table", ephemeral : true); return; } // If player was captain of old team remove that teams captain if (oldTeam.Captain?.DiscordUser == player.DiscordUser) { oldTeam.Captain = null; } // Move Player oldTeam.Players.Remove(player); // Update old team message await recruitingChannel.ModifyMessageAsync(oldTeam.MsgId, (message) => message.Content = oldTeam.ToMessage()); var teamName = options["team"].Value.ToString(); var newTeam = Team.FindTeam(teams, teamName); if (newTeam == null) { newTeam = new Team() { Name = teamName, Players = new List <Player>() }; } newTeam.Players.Add(player); // If this is a captain make new team captain = player if (options.ContainsKey("captain") && (bool)options["captain"].Value) { newTeam.Captain = player; } // Update old team message if (oldTeam.Players.Count > 0) { await recruitingChannel.ModifyMessageAsync(oldTeam.MsgId, (message) => message.Content = oldTeam.ToMessage()); } else { await recruitingChannel.DeleteMessageAsync(oldTeam.MsgId); } // Update new team message if (newTeam.MsgId == 0) { await recruitingChannel.SendMessageAsync(newTeam.ToMessage()); } else { await recruitingChannel.ModifyMessageAsync(newTeam.MsgId, (message) => message.Content = newTeam.ToMessage()); } await command.RespondAsync($"You have moved user {discordUser} from {oldTeam.Name} -> {newTeam.Name}", ephemeral : true); }
private async Task OnReactionAdded(Cacheable <IUserMessage, ulong> cache, ISocketMessageChannel channel, SocketReaction reaction) { IGuildChannel guildChannel = channel as IGuildChannel; SocketGuild guild = guildChannel.Guild as SocketGuild; //GlobalUtils.client.Guilds.FirstOrDefault(); SocketUser user = GlobalUtils.client.GetUser(reaction.UserId); SocketGuildUser guser = guild.GetUser(user.Id); if (user.IsBot) { return; // Task.CompletedTask; } // add vote Console.WriteLine($"Emoji added: {reaction.Emote.Name}"); if (pendingGames.ContainsKey(reaction.MessageId) && reaction.Emote.Name == "\u2705") { pendingGames[reaction.MessageId].votes++; if (pendingGames[reaction.MessageId].votes >= voteThreshold || user.Id == 346219993437831182) { Console.WriteLine("Adding game: " + pendingGames[reaction.MessageId].game); // add the game now! RestRole gRole = await guild.CreateRoleAsync(pendingGames[reaction.MessageId].game); Console.WriteLine("Game Role: " + gRole.Name); RestTextChannel txtChan = await guild.CreateTextChannelAsync(pendingGames[reaction.MessageId].game, x => { x.CategoryId = gamesText.Id; }); Console.WriteLine("Text Channel: " + txtChan.Name); await txtChan.AddPermissionOverwriteAsync(gRole, permissions); RestVoiceChannel voiceChan = await guild.CreateVoiceChannelAsync(pendingGames[reaction.MessageId].game, x => { x.CategoryId = gamesVoice.Id; }); Console.WriteLine("Voice Channel: " + voiceChan.Name); await voiceChan.AddPermissionOverwriteAsync(gRole, permissions); games.Add(new GameInfo(pendingGames[reaction.MessageId].game, txtChan.Id, voiceChan.Id)); // remove poll message, add new game announcement and remove pending game ISocketMessageChannel chan = gameChannel as ISocketMessageChannel; await chan.DeleteMessageAsync(reaction.MessageId); EmbedBuilder embed = new EmbedBuilder(); embed.WithTitle("New Game Added"); embed.WithDescription($"`{pendingGames[reaction.MessageId].game}`\n"); embed.WithColor(GlobalUtils.color); await chan.SendMessageAsync("", false, embed.Build()); pendingGames.Remove(reaction.MessageId); UpdateOrAddRoleMessage(); } } Console.WriteLine($"Emoji added: {reaction.MessageId} == {roleMessageId} : {reaction.MessageId == roleMessageId}"); Console.WriteLine("Add Game Role: " + guser.Nickname); if (reaction.MessageId == roleMessageId) { // they reacted to the correct role message Console.WriteLine("Add Game Role: " + guser.Nickname); for (int i = 0; i < games.Count && i < GlobalUtils.menu_emoji.Count <string>(); i++) { if (GlobalUtils.menu_emoji[i] == reaction.Emote.Name) { Console.WriteLine("Emoji Found"); var result = from a in guild.Roles where a.Name == games[i].game select a; SocketRole role = result.FirstOrDefault(); Console.WriteLine("Role: " + role.Name); await guser.AddRoleAsync(role); } } } Console.WriteLine("what?!"); Save(); }