public async Task HelpList() { await Context.Message.AddReactionAsync(Emote.Parse("<:ThinkRadiance:567800282797309957>")); if (Global.HelpHandler.Item1 != null) { try { await Global.HelpHandler.Item1.DeleteAsync(); } catch { } } EmbedBuilder builder = new EmbedBuilder(); builder .WithTitle(Text("help_header").ToString()) .WithColor(Color.DarkBlue) .AddField(Text("help_titles")[0].ToString(), Text("help")[0].ToString()) .WithFooter(Text("help_page") + "1/" + (Text("help").AllNodes.Count() - 1).ToString()); Discord.Rest.RestUserMessage a = await Context.Channel.SendMessageAsync("", false, builder.Build()); await a.AddReactionAsync(new Emoji("◀")); await a.AddReactionAsync(new Emoji("▶")); Global.HelpHandler = (a, 0); }
public async Task StartAsync([Summary("Event type")] string type, [Summary("Note for the DKP Log")][Remainder] string note) { if (Program.AttendanceEvent.active) { await ReplyAsync($"Unable to start event, another event is still running: {Program.AttendanceEvent.type} {Program.AttendanceEvent.note}"); return; } string[] types = Config.Global.Commands.Attendance.ValidAttendanceTypes; bool valid = false; foreach (string validType in types) { if (type == validType) { valid = true; break; } } if (!valid) { await ReplyAsync($"I don't recognize attendance type {type}"); return; } Discord.Rest.RestUserMessage message = await Context.Channel.SendMessageAsync($"<@&{Config.Global.Commands.Attendance.MemberRole}> Attendance tracking for {type} {note} has begun, click the check mark to be counted!"); Program.AttendanceEvent = new SAttendanceEvent(type, note, message.Id); await message.AddReactionAsync(new Emoji(Config.Global.Commands.Attendance.HereEmoji)); await message.PinAsync(); }
public async void AddReactionsAsync(List <string> Reactions, Discord.Rest.RestUserMessage Message) { foreach (var Reaction in Reactions) { if (Reaction != "" && Reaction != null) { if (Reaction.Contains("<:") && Reaction.Contains(":") && Reaction.Contains(">")) { await Message.AddReactionAsync(Emote.Parse(Reaction)); } else { await Message.AddReactionAsync(new Emoji(Reaction)); } } } }
public async Task FlipAsync([Remainder] string input) { int delay = 15; string emote = null; int bet = 0; string side = null; var userInfo = (IGuildUser)Context.User; string userName = null; Discord.Rest.RestUserMessage mainMessage = null; Embed embedBuilt = null; if (userInfo.Nickname != null) { userName = userInfo.Nickname; } else { userName = Context.User.Username; } var footer = new EmbedFooterBuilder { Text = "Cody by Ayla / Alsekwolf#0001" }; var author = new EmbedAuthorBuilder { IconUrl = Context.User.GetAvatarUrl(), Name = $"{userName} entered a game of coin flip." }; var embed = new EmbedBuilder { Author = author, Color = Color.Magenta, Footer = footer, Timestamp = DateTimeOffset.Now }; if (!Services.CommandDelay.IncomingRequest(Context.User.Id.ToString(), delay)) { string activeUser = _activeUsers.FirstOrDefault(s => s == Context.User.Id.ToString()); if (activeUser == null) { _activeUsers.Add(Context.User.Id.ToString()); } if (activeUser != null) { await Context.Message.DeleteAsync(); return; } embed.WithDescription( $"please wait longer between *investing*. \nYour bet will be sent when the delay is up. \nReact with the stop emote to cancel."); embedBuilt = embed.Build(); mainMessage = await Context.Channel.SendMessageAsync(embed : embedBuilt); if (Emote.TryParse(StopEmote, out var stopEmoteParsed)) { await mainMessage.AddReactionAsync(stopEmoteParsed); } Services.CommandDelay.User tempUser = Services.CommandDelay.Users.FirstOrDefault(User => User.Username == Context.User.Id.ToString()); try { while ((DateTime.Now - tempUser.LastRequest).TotalSeconds <= delay) { await Task.Delay(1000); } int count = 0; foreach (string y in _activeUsers.FindAll(x => x == Context.User.Id.ToString())) // returns the value of all hits} { _activeUsers.Remove(y); count++; } var userList = await mainMessage.GetReactionUsersAsync(stopEmoteParsed, int.MaxValue).FlattenAsync(); if (userList.Any(u => u.Id == Context.User.Id)) { return; } await mainMessage.RemoveAllReactionsAsync(); } catch (Exception e) { Console.WriteLine("DelayCommand error: " + e.Message); throw; } } var SQL = new SQLFunctions.Main(); var userData = SQL.LoadUserData(Context.User); if (input.ContainsAny(" ")) { var splitInput = input.Split(' '); if (splitInput[0].All(char.IsDigit)) { bet = Int32.Parse(splitInput[0]); side = splitInput[1]; } if (splitInput[1].All(char.IsDigit)) { bet = Int32.Parse(splitInput[1]); side = splitInput[0]; } if (splitInput[0].ContainsAny("all")) { bet = userData.cash; side = splitInput[1]; } if (splitInput[1].ContainsAny("all")) { bet = userData.cash; side = splitInput[0]; } if (side.ContainsAny("head", "heads", "h")) { side = "heads"; } if (side.ContainsAny("tail", "tailss", "t")) { side = "tails"; } } else { if (input.All(char.IsDigit)) { bet = Int32.Parse(input); side = "heads"; } if (input.ContainsAny("all")) { bet = userData.cash; side = "heads"; } } if (bet == 0) { embed.WithDescription($"You can't bet 0, that's not how this works!!'"); embedBuilt = embed.Build(); if (mainMessage != null) { await mainMessage.ModifyAsync(msg => msg.Embed = embedBuilt); } else { await Context.Channel.SendMessageAsync(embed : embedBuilt); } return; } if (side == null) { embed.WithDescription($"something went wrong, please try again."); embedBuilt = embed.Build(); if (mainMessage != null) { await mainMessage.ModifyAsync(msg => msg.Embed = embedBuilt); } else { await Context.Channel.SendMessageAsync(embed : embedBuilt); } return; } if (userData.cash >= bet) { embed.WithAuthor($"{userName} spent ${bet} and chose {side}", Context.User.GetAvatarUrl()); embed.WithDescription($"The coin spins.... {FlipEmote}"); embedBuilt = embed.Build(); if (mainMessage != null) { await mainMessage.ModifyAsync(msg => msg.Embed = embedBuilt); } else { mainMessage = await Context.Channel.SendMessageAsync(embed : embedBuilt); } await Task.Delay(2250); int randomNumber = RandomNumber.Between(0, 100); if (randomNumber > 50) { if (side == "heads") { emote = TailsEmote; } else { emote = HeadsEmote; } embed.WithDescription($"The coin spins.... {emote} and **{userName}** lost it all... :c"); embedBuilt = embed.Build(); await mainMessage.ModifyAsync(msg => msg.Embed = embedBuilt); userData.cash = userData.cash - bet; SQL.SaveUserData(Context.User, userData); } if (randomNumber < 50) { if (side == "heads") { emote = HeadsEmote; } else { emote = TailsEmote; } embed.WithDescription($"The coin spins.... {emote} and **{userName}** won **${bet}** c:"); embedBuilt = embed.Build(); await mainMessage.ModifyAsync(msg => msg.Embed = embedBuilt); userData.cash = userData.cash + bet; SQL.SaveUserData(Context.User, userData); } } else { embed.WithDescription($"you probably don't have enough cash. \nYou currently have **${userData.cash}**"); embedBuilt = embed.Build(); if (mainMessage != null) { await mainMessage.ModifyAsync(msg => msg.Embed = embedBuilt); } else { await Context.Channel.SendMessageAsync(embed : embedBuilt); } } }
public override async Task OnExecuteFromDiscord(SocketGuild guild, SocketUser user, SocketTextChannel channel, SocketMessage messageobject, string fullmessage, string arguments_string, List <string> arguments) { int page = 0; List <string> pages = new List <string>(); Emoji em1 = new Emoji("\u23EE"); Emoji em2 = new Emoji("\u23ED"); String currentPage = "```A list of known command categories:"; List <CmdCategory> categories = new List <CmdCategory>(); foreach (CmdCategory cat in Bot.GetBot().CmdCategories) { if (arguments.Count != 0) { if (cat.name.ToLower() != arguments[0].ToLower()) { continue; } } if (!categories.Contains(cat)) { categories.Add(cat); } } foreach (CmdCategory cat in Bot.GetBot().CmdCategories) { if (arguments.Count != 0) { if (!cat.name.ToLower().StartsWith(arguments[0].ToLower())) { continue; } } if (!categories.Contains(cat)) { categories.Add(cat); } } foreach (CmdCategory cat in Bot.GetBot().CmdCategories) { if (arguments.Count != 0) { if (!cat.name.ToLower().Contains(arguments[0].ToLower())) { continue; } } if (!categories.Contains(cat)) { categories.Add(cat); } } foreach (CmdCategory cat in Bot.GetBot().CmdCategories) { if (arguments.Count != 0) { if (!cat.description.ToLower().StartsWith(arguments[0].ToLower())) { continue; } } if (!categories.Contains(cat)) { categories.Add(cat); } } foreach (CmdCategory cat in Bot.GetBot().CmdCategories) { if (arguments.Count != 0) { if (!cat.description.ToLower().Contains(arguments[0].ToLower())) { continue; } } if (!categories.Contains(cat)) { categories.Add(cat); } } foreach (CmdCategory cat in categories) { if (currentPage.Length + 3 >= 2000) { currentPage += "```"; pages.Add(currentPage); currentPage = "```A list of known command categories (page " + pages.Count + "):"; } currentPage += ("\n - " + cat.name + " - " + cat.description); } if (currentPage.Length != ("```A list of known command categories (page " + pages.Count + "):").Length) { currentPage += "```"; pages.Add(currentPage); } Discord.Rest.RestUserMessage message = await channel.SendMessageAsync(pages[page]); Func <Cacheable <IUserMessage, ulong>, ISocketMessageChannel, SocketReaction, Task> handler = new Func <Cacheable <IUserMessage, ulong>, ISocketMessageChannel, SocketReaction, Task>((arg1, arg2, arg3) => { if (arg3.MessageId == message.Id && arg3.Channel.Id == message.Channel.Id) { if (arg3.Emote.Name == em1.Name) { bool changed = false; var v = message.GetReactionUsersAsync(em1, int.MaxValue).GetAsyncEnumerator(); while (true) { if (v.Current != null) { foreach (IUser usr in v.Current) { if (!usr.Id.Equals(Bot.GetBot().client.CurrentUser.Id)) { message.RemoveReactionAsync(em1, usr).GetAwaiter().GetResult(); changed = true; } } } if (!v.MoveNextAsync().GetAwaiter().GetResult()) { break; } } if (changed) { page--; var oldmsg = message; message = channel.SendMessageAsync(pages[page]).GetAwaiter().GetResult(); oldmsg.DeleteAsync().GetAwaiter().GetResult(); if (page != 0) { message.AddReactionAsync(em1).GetAwaiter().GetResult(); } if (page != pages.Count - 1) { message.AddReactionAsync(em2).GetAwaiter().GetResult(); } } } if (arg3.Emote.Name == em2.Name) { bool changed = false; var v = message.GetReactionUsersAsync(em2, int.MaxValue).GetAsyncEnumerator(); while (true) { if (v.Current != null) { foreach (IUser usr in v.Current) { if (!usr.Id.Equals(Bot.GetBot().client.CurrentUser.Id)) { message.RemoveReactionAsync(em1, usr).GetAwaiter().GetResult(); changed = true; } } } if (!v.MoveNextAsync().GetAwaiter().GetResult()) { break; } } if (changed) { page++; var oldmsg = message; message = channel.SendMessageAsync(pages[page]).GetAwaiter().GetResult(); oldmsg.DeleteAsync().GetAwaiter().GetResult(); if (page != 0) { message.AddReactionAsync(em1).GetAwaiter().GetResult(); } if (page != pages.Count - 1) { message.AddReactionAsync(em2).GetAwaiter().GetResult(); } } } } return(null); }); Bot.GetBot().client.ReactionAdded += handler; Bot.GetBot().client.MessageDeleted += (arg11, arg22) => { if (arg11.Id == message.Id) { Bot.GetBot().client.ReactionAdded -= handler; } return(null); }; if (pages.Count != 1) { if (page != pages.Count) { await message.AddReactionAsync(em2); } } }