public async Task CreateLinkedPlayerCommand( [Summary("The player's name.")] string name, [Summary("The ID of the player.")] ulong id, [Summary("The displayed TrueSkill of the player.")] double skill = double.NaN, [Summary("The RD of the player.")] double rd = double.NaN ) { var np = createPlayer(name, skill, rd); var user = Program.DiscordIO.GetUser(id); if (user == null) { await ReplyAsync(EmbedHelper.GenerateErrorEmbed($"The ID `{id}` is invalid.")); return; } np.LinkDiscord(id); await np.UpdateRank(true); Program.Controller.CurLeaderboard.AddPlayer(np); await ReplyAsync(EmbedHelper.GenerateSuccessEmbed( $"Added player **{name}** with skill {np.DisplayedSkill} RD {np.Sigma}," + $" and linked them to the Discord User {user.Mention}.", "Player ID: " + np.UUId) ); }
public async Task LinkPlayerCommand( [Summary("The player's name.")] string name, [Summary("The Discord ID of the player.")] ulong id ) { var player = Program.CurLeaderboard.FuzzySearch(name); if (player == null) { await ReplyAsync(EmbedHelper.GenerateErrorEmbed($"Could not find the player **{name}**.")); return; } var user = Program.DiscordIO.GetUser(id); if (user == null) { await ReplyAsync(EmbedHelper.GenerateErrorEmbed($"The ID `{id}` is invalid.")); return; } player.LinkDiscord(id); await player.UpdateRank(true); await ReplyAsync(EmbedHelper.GenerateSuccessEmbed($"**{player.IGN}** is now linked to **{user.Username}#{user.DiscriminatorValue}**")); }
public async Task CreateTournamentCommand( [Summary("The name of the tournament.")] string tournamentName, [Summary("The format of the tournament.")] string format, [Summary("The UTC time of the tournament, in the form HHMM (ie, 1600 for 4PM UTC)")] ushort utcTime, [Summary("The calendar date of the tournament in DD/MM/YYYY, DD/MM, or DD. The missing fields will be autofilled.")] string calendarDate = "" ) { var tourney = Tournament.GenerateTournament(tournamentName, utcTime, calendarDate, format); var msgTask = SendProgressAsync(EmbedHelper.GenerateInfoEmbed(":arrows_counterclockwise: Created tournament. Creating on challonge...")); var msg = await msgTask; var ct = await tourney.SetUpChallonge(); var atTask = Program.Controller.AddTournament(tourney); await atTask; await msg.DeleteAsync(); await ReplyAsync(EmbedHelper.GenerateSuccessEmbed( $"Created the tournament **{tournamentName}**:" + Environment.NewLine + Environment.NewLine + $"Date: {tourney.GetStartTimeStr()}" + Environment.NewLine + $"Challonge URL: {ct.FullChallongeUrl}" )); await SetCurrentTournamentCommand(Program.Controller.Tournaments.Count); }
public Embed GenerateModuleEmbed(ModuleInfo module) { var f = new EmbedBuilder(); f.Title = module.Name; f.Description = module.Summary; f.Color = Discord.Color.Blue; bool displayedAny = false; foreach (var cmd in module.Commands) { if (shouldDisplay(cmd)) { displayedAny = true; f.AddField(GenerateCommandUsage(cmd) + " " + GenerateCommandAliases(cmd), cmd.Summary ?? "No description"); } } if (displayedAny) { return(f.Build()); } else { return(EmbedHelper.GenerateErrorEmbed("You do not have permission to view the commands under this query.")); } }
// allow this code to also be used for !tournamentstartmatch (!tsm) public static async Task <Tuple <PendingMatch, Embed> > StartMatch(string team1, string team2, bool force, bool isTourney = false) { try { Team t1; Team t2; try { t1 = StrToTeam(team1); t2 = StrToTeam(team2); } catch (Exception e) { return(new Tuple <PendingMatch, Embed>(null, EmbedHelper.GenerateErrorEmbed(e.Message))); } var t1_s = string.Join(", ", t1.Players.Select(x => x.IGN)); var t2_s = string.Join(", ", t2.Players.Select(x => x.IGN)); var match = await Program.Controller.StartMatchAction(t1, t2, isTourney, force); if (match == null) { return(new Tuple <PendingMatch, Embed>(null, EmbedHelper.GenerateErrorEmbed( $"One or more of the players you specified are already playing. Please set `force` to `true` if you wish to override this protection."))); } string output = $"Started the match between **{t1_s}** and **{t2_s}**."; return(new Tuple <PendingMatch, Embed>(match, EmbedHelper.GenerateSuccessEmbed(output))); } catch (Exception e) { return(new Tuple <PendingMatch, Embed>(null, EmbedHelper.GenerateErrorEmbed(e.Message))); } }
public async Task HelpCommand([Summary("The command to search for.")] string query, [Summary("Whehter or not to force search for a command.")] bool forceCmd = false) { query = query.ToLower(); // first search modules var moduleResult = Program.DiscordIO.Commands.Modules.FirstOrDefault(m => query.Equals(GetModuleQueryableName(m))); if (moduleResult != null && !forceCmd) { await ReplyAsync(GenerateModuleEmbed(moduleResult)); return; } // now search modules var cmdResult = Program.DiscordIO.Commands.Search(Context, query); if (!cmdResult.IsSuccess || cmdResult.Commands == null) { await ReplyAsync(EmbedHelper.GenerateErrorEmbed($"Could not find the command {(forceCmd ? "" : "or module ")}**{query}**.")); return; } var result_ = cmdResult.Commands.Where(c => c.Command.Summary == null || !c.Command.Summary.Contains("(Easter Egg)")).ToList(); string prefix = Program.prefix.ToString(); var builder = new EmbedBuilder() { Color = new Color(114, 137, 218), }; sbyte displayedCnt = 0; foreach (var match in result_) { var cmd = match.Command; if (shouldDisplay(cmd)) { ++displayedCnt; builder.AddField(x => { x.Name = GenerateCommandTitle(cmd); x.Value = GenerateHelpText(cmd); x.IsInline = false; }); } } if (displayedCnt != 0) { await ReplyAsync(builder.Build()); } else { builder.Description = $"Found **{result_.Count}** command{(result_.Count == 1 ? "" : "s")}:"; await ReplyAsync(EmbedHelper.GenerateErrorEmbed("You do not have permission to view this command.")); } }
public async Task RemoveAchievementCommand( [Summary("The name, UUID or Discord message ID of the achievement.")] string achievement, [Remainder][Summary("The player to revoke the achievement from.")] string players ) { var achv = Program.Controller.Achievements.FindAchievement(achievement); if (achv == null) { await ReplyAsync(EmbedHelper.GenerateErrorEmbed($"Could not find the achievement from the query **{achievement}**.")); return; } var teams = TournamentCommands.StrListToTeams(players); var output = ""; foreach (var t in teams) { foreach (var p in t.Players) { if (await achv.AddPlayer(p)) { output += p.IGN + Environment.NewLine; } else { await ReplyAsync(EmbedHelper.GenerateWarnEmbed($"Could not revoke the player **{p.IGN}** of the achievement **{achv.Name}**.")); } } } await ReplyAsync(EmbedHelper.GenerateSuccessEmbed( $"Successfully revoked the following players of the achievement **{achv.Name}**:" + Environment.NewLine + Environment.NewLine + output)); }
public Task FixCAGCommand() { var rand = new Random(); var num = rand.Next(); return(ReplyAsync(EmbedHelper.GenerateSuccessEmbed($"Fixed a total of **{num}** CAGs."))); }
public async Task DeleteChannelsCommand() { var msg = await Program.DiscordIO.SendMessage("", Context.Channel, EmbedHelper.GenerateInfoEmbed($":arrows_counterclockwise: Deleting channels - please wait...")); await((SocketTextChannel)Program.Config.GetAchievementsChannel()).DeleteAsync(); await((SocketTextChannel)Program.Config.GetCommandChannel()).DeleteAsync(); await((SocketTextChannel)Program.Config.GetLogsChannel()).DeleteAsync(); await((SocketTextChannel)Program.Config.GetActiveMatchesChannel()).DeleteAsync(); await((SocketTextChannel)Program.Config.GetLeaderboardChannel()).DeleteAsync(); await((SocketTextChannel)Program.Config.GetLogsChannel()).DeleteAsync(); await((SocketTextChannel)Program.Config.GetTourneysChannel()).DeleteAsync(); await((SocketTextChannel)Program.Config.GetSignupLogsChannel()).DeleteAsync(); await((SocketTextChannel)Program.Config.GetSignupsChannel()).DeleteAsync(); Program.Config.LogsChannelId = 0; Program.Config.AchievementsChannelId = 0; Program.Config.CommandChannelId = 0; Program.Config.LeaderboardChannelId = 0; Program.Config.HistoryChannelId = 0; Program.Config.ActiveMatchesChannelId = 0; Program.Config.TourneysChannelId = 0; Program.Config.SignupLogsChannelId = 0; Program.Config.SignupsChannelId = 0; await msg.DeleteAsync(); await ReplyAsync(EmbedHelper.GenerateSuccessEmbed("Deleted the bot channels.")); }
public async Task CreateAchievementCommand( [Summary("The achievement's name.")] string name, [Summary("The description of the achievement.")] string description ) { var result = await Program.Controller.Achievements.AddAchievement(name, description); if (result) await ReplyAsync(EmbedHelper.GenerateSuccessEmbed($"Successfully added the achievement **{name}**.")); else await ReplyAsync(EmbedHelper.GenerateErrorEmbed($"Could not create the achievement **{name}**. Please try again.")); }
public Task ViewPermittedRoleCommand() { var sb = new StringBuilder(); sb.Append("**The following roles are permitted:**" + Environment.NewLine + Environment.NewLine); foreach (var r in Program.Config.PermittedRoleNames) { sb.Append($"{r}{Environment.NewLine}"); } return(ReplyAsync(EmbedHelper.GenerateSuccessEmbed(sb.ToString()))); }
public async Task ResendAchvsCommand() { var msg = await SendProgressAsync( EmbedHelper.GenerateInfoEmbed($":arrows_counterclockwise: Resending all achievements...")); foreach (var a in Program.Controller.Achievements.AchievementsList) { await a.DeleteMessage(); await a.SendMessage(); } await ReplyAsync(EmbedHelper.GenerateSuccessEmbed($"Resent {Program.Controller.Achievements.AchievementsList.Count()} achievement(s).")); }
public async Task DeleteAchievementCommand( [Summary("The name, UUID or Discord message ID of the achievement to delete.")] string achievement ) { var achv = Program.Controller.Achievements.FindAchievement(achievement); if (achv != null) { if (await Program.Controller.Achievements.DeleteAchievement(achv)) { await ReplyAsync(EmbedHelper.GenerateSuccessEmbed($"Deleted the achievement **{achv.Name}**.")); } else { await ReplyAsync(EmbedHelper.GenerateErrorEmbed($"Could not delete the achievement **{achv.Name}**.")); } } else { await ReplyAsync(EmbedHelper.GenerateErrorEmbed($"Could not find the achievement from the query **{achievement}**.")); } }
public async Task AutoCreatePlayer( [Remainder][Summary("The player's name. Leave empty to set to their Discord username.")] string name = null ) { if (Program.CurLeaderboard.LatestJoinedPlayer == null) { await ReplyAsync(EmbedHelper.GenerateErrorEmbed("Could not identify the latest player who has joined.")); return; } (string Name, ulong DiscordID)p = ((string Name, ulong DiscordID))Program.CurLeaderboard.LatestJoinedPlayer; await CreateLinkedPlayerCommand(string.IsNullOrWhiteSpace(name)?p.Name : name, p.DiscordID); }
public async Task EditAchievementCommand( [Summary("The name, UUID or Discord message ID of the achievement.")] string achievement, [Summary("The achievement's name.")] string name, [Summary("The description of the achievement.")] string description ) { var achv = Program.Controller.Achievements.FindAchievement(achievement); if (achv == null) { await ReplyAsync(EmbedHelper.GenerateErrorEmbed($"Could not find the achievement from the query **{achievement}**.")); return; } await achv.Edit(name, description); await ReplyAsync(EmbedHelper.GenerateSuccessEmbed($"Successfully edited the achievement **{name}**.")); }
public async Task CreatePlayerCommand( [Summary("The player's name.")] string name, [Summary("The displayed TrueSkill of the player.")] double skill = double.NaN, [Summary("The RD of the player.")] double rd = double.NaN ) { var np = createPlayer(name, skill, rd); await np.UpdateRank(true); Program.Controller.CurLeaderboard.AddPlayer(np); await ReplyAsync(EmbedHelper.GenerateSuccessEmbed( $"Added player **{name}** with skill {np.DisplayedSkill} RD {np.Sigma}.", "Player ID: " + np.UUId) ); }
public async Task DeletePlayer([Summary("The player's name, ID, or Discord ID.")] string name) { var player = FindPlayer(name); if (player == null) { await ReplyAsync(EmbedHelper.GenerateErrorEmbed($"Could not find the user with name or ID `{name}`.")); return; } player.MarkedForDeletion = true; Program.CurLeaderboard.InvokeChange(); await ReplyAsync(EmbedHelper.GenerateSuccessEmbed($"**{player.IGN}** has been removed from the leaderboard.")); }
public async Task UnlinkPlayerCommand( [Summary("The player's name, ID, or Discord ID.")] string name ) { var player = FindPlayer(name); if (player == null) { await ReplyAsync(EmbedHelper.GenerateErrorEmbed($"Could not find the user with name or ID `{name}`.")); return; } player.UnlinkDiscord(); await ReplyAsync(EmbedHelper.GenerateSuccessEmbed($"**{player.IGN}** has been unlinked.")); }
public async Task EditPlayerCommand( [Summary("The player's name, ID, or Discord ID.")] string name, [Summary("What to change the player's name to.")] string newName, [Summary("What to change the player's TrueSkill to.")] string newTs = "~", [Summary("What to change the player's RD to.")] string newRd = "~", [Summary("What to change the player's alias to.")] string newAlias = "~" ) { var player = FindPlayer(name); if (player == null) { await ReplyAsync(EmbedHelper.GenerateErrorEmbed($"Could not find the user with name or ID `{name}`.")); return; } if (!newName.Equals("~")) { player.IGN = newName; } double d_newSigma; if (!newTs.Equals("~") && Double.TryParse(newRd, out d_newSigma)) { player.Sigma = d_newSigma; } double d_newTs; if (!newTs.Equals("~") && Double.TryParse(newTs, out d_newTs)) { player.Mu = d_newTs + player.Sigma * Program.Config.TrueSkillDeviations; } if (!newAlias.Equals("~")) { player.Alias = newAlias; } Program.CurLeaderboard.InvokeChange(); await ReplyAsync(EmbedHelper.GenerateSuccessEmbed($"**{player.IGN}**'s data has been updated to the following: {Environment.NewLine}{Environment.NewLine}" + player.GenerateSummary())); }
public async Task CreateTournamentCommand( [Summary("The name of the tournament.")] string tournamentName, [Summary("The UTC time of the tournament, in the form HHMM (ie, 1600 for 4PM UTC)")] ushort utcTime, [Summary("The calendar date of the tournament in DD/MM/YYYY, DD/MM, or DD. The missing fields will be autofilled.")] string calendarDate = "" ) { var tourney = Tournament.GenerateTournament(tournamentName, utcTime, calendarDate); await Program.Controller.AddTournament(tourney); await ReplyAsync(EmbedHelper.GenerateSuccessEmbed( $"Created the tournament **{tournamentName}**:" + Environment.NewLine + Environment.NewLine + $"Date: {tourney.GetStartTimeStr()}" + Environment.NewLine )); // set to this await SetCurrentTournamentCommand(Program.Controller.Tournaments.Count); }
public async Task ViewTournaments() { var tourneys = Program.Controller.Tournaments; if (tourneys == null || tourneys.Count == 0) { await ReplyAsync(EmbedHelper.GenerateInfoEmbed("There are no tournaments.")); return; } var eb = new EmbedBuilder().WithColor(Discord.Color.Blue); for (int i = 0; i < tourneys.Count; ++i) { eb.AddField((i + 1) + " - " + tourneys[i].Name, "Time: " + tourneys[i].GetStartTimeStr()); } await ReplyAsync(eb.Build()); }
public async Task PingCommand() { var timeAuthorSent = Context.Message.Timestamp; var timeReceivedAuthor = DateTimeOffset.UtcNow; var msg = await Program.DiscordIO.SendMessage("", Context.Channel, EmbedHelper.GenerateInfoEmbed(":clock1: Ping received. Measuring latency...")); var timeSent = msg.Timestamp; var diff1 = Math.Max(0, (timeReceivedAuthor - timeAuthorSent).Milliseconds); var diff2 = Math.Max(0, (timeSent - timeReceivedAuthor).Milliseconds); await Task.WhenAll( ReplyAsync(EmbedHelper.GenerateInfoEmbed($"Gateway receive latency: **{diff1}ms**" + Environment.NewLine + $"Gateway send latency: **{diff2}ms**" + Environment.NewLine + $"Total ping: **{diff1 + diff2}ms**", ":ping_pong: Pong!", null)), msg.DeleteAsync() ); }
public async Task SetupChannelsCommand() { var msg = await Program.DiscordIO.SendMessage("", Context.Channel, EmbedHelper.GenerateInfoEmbed($":arrows_counterclockwise: Setting up channels - please wait...")); // Create Categories. var achievementsCat = (await Program.DiscordIO.CreateCategory("Achievements")).Id; var manageCat = (await Program.DiscordIO.CreateCategory("Skillbot Management")).Id; var skillCat = (await Program.DiscordIO.CreateCategory("Matches")).Id; var tourneyCat = (await Program.DiscordIO.CreateCategory("Tournaments")).Id; // Create channels. var achievementsId = (await Program.DiscordIO.CreateChannel("achievements", achievementsCat)).Id; var commandsId = (await Program.DiscordIO.CreateChannel("commands", manageCat)).Id; var logsId = (await Program.DiscordIO.CreateChannel("logs", manageCat)).Id; var leaderboardId = (await Program.DiscordIO.CreateChannel("leaderboard", skillCat)).Id; var historyId = (await Program.DiscordIO.CreateChannel("match-history", skillCat)).Id; var activeMatchesId = (await Program.DiscordIO.CreateChannel("active-matches", manageCat)).Id; var tourneysId = (await Program.DiscordIO.CreateChannel("tournaments", tourneyCat)).Id; var signupLogsId = (await Program.DiscordIO.CreateChannel("signup-log", tourneyCat)).Id; var signupsId = (await Program.DiscordIO.CreateChannel("signups", tourneyCat, true)).Id; // Save to config. Program.Config.AchievementsChannelId = achievementsId; Program.Config.CommandChannelId = commandsId; Program.Config.LogsChannelId = logsId; Program.Config.LeaderboardChannelId = leaderboardId; Program.Config.HistoryChannelId = historyId; Program.Config.ActiveMatchesChannelId = activeMatchesId; Program.Config.TourneysChannelId = tourneysId; Program.Config.SignupLogsChannelId = signupLogsId; Program.Config.SignupsChannelId = signupsId; await msg.DeleteAsync(); Program.CurLeaderboard.InvokeChange(); await ReplyAsync(EmbedHelper.GenerateSuccessEmbed("Succesfully created all the required channels. Basic permissions have been set up for the channels. Change the permissions as you please.")); }
public async Task FindPlayerCommand([Summary("The player's name, ID, or Discord ID.")] string name) { var player = FindPlayer(name); if (player == null) { await ReplyAsync(EmbedHelper.GenerateErrorEmbed($"Could not find the user with name or ID `{name}`.")); return; } var embed = new EmbedBuilder().WithTitle(player.IGN).WithColor(Discord.Color.Green); embed.AddField("Info", player.GenerateSummary()); if (player.DiscordUser != null) { embed.ThumbnailUrl = player.DiscordUser.GetAvatarUrl(); } await ReplyAsync(embed.Build()); }
public Task LinkChannelsCommand( [Summary("The ID of the achievements channel.")] ulong achievementsId, [Summary("The ID of the commands channel.")] ulong commandsId, [Summary("The ID of the logs channel.")] ulong logsId, [Summary("The ID of the leaderboard channel.")] ulong leaderboardId, [Summary("The ID of the match history channel.")] ulong historyId, [Summary("The ID of the active matches channel.")] ulong activeMatchesId, [Summary("The ID of the tournaments channel.")] ulong tourneysId, [Summary("The ID of the tournament signups logs channel.")] ulong signupLogsId, [Summary("The ID of the tournament signups channel.")] ulong signupsId) { Program.Config.CommandChannelId = commandsId; Program.Config.LogsChannelId = logsId; Program.Config.LeaderboardChannelId = leaderboardId; Program.Config.HistoryChannelId = historyId; Program.Config.ActiveMatchesChannelId = activeMatchesId; Program.Config.TourneysChannelId = tourneysId; Program.Config.SignupLogsChannelId = signupLogsId; Program.Config.SignupsChannelId = signupsId; Program.CurLeaderboard.InvokeChange(); return(ReplyAsync(EmbedHelper.GenerateSuccessEmbed("Succesfully linked."))); }
public Task DecipherCommand([Summary("The string to decipher.")][Remainder] string toDecipher) { return(ReplyAsync(EmbedHelper.GenerateErrorEmbed($"Failed to decipher the message." + Environment.NewLine + Environment.NewLine + "**Most Likely Cause:**" + Environment.NewLine + "The message was composed by Cistic."))); }
public Task BetterBotCommand(string a) { return(ReplyAsync(EmbedHelper.GenerateInfoEmbed($"OpenSkillBot is superior."))); }
public Task RemovePermittedRoleCommand([Remainder][Summary("The name of the role to remove.")] string roleName) { Program.Config.PermittedRoleNames.Remove(roleName); Program.SerializeConfig(); return(ReplyAsync(EmbedHelper.GenerateSuccessEmbed($"**{roleName}** is no longer a permitted role."))); }
public Task AddPermittedRoleCommand([Remainder][Summary("The name of the role to add.")] string roleName) { Program.Config.PermittedRoleNames.Add(roleName.Trim().ToLower()); Program.SerializeConfig(); return(ReplyAsync(EmbedHelper.GenerateSuccessEmbed($"Permitted users with the role **{roleName}**."))); }