public ActionResult Guild() { ViewBag.Message = ""; var model = new Models.Guild(); return(View(model)); }
public static Tuple <string, Embed> Response(Models.Guild guild) { var embed = new EmbedBuilder { Author = new EmbedAuthorBuilder { Name = "Admin Guide" }, Description = "These commands are only callable by admin users.\n\n" + "Support Server: https://discord.gg/KxNzKFN \n\n" }; embed.AddField("!a config match {type}", "Toggle the bot's automatic card name detection between three types:\n" + "**brackets** - Look for card names between brackets: `I'm going to try [[axe]].`\n" + "**singleBracket** - Look for card names between single bracket: `I'm going to try [axe].`\n" + "**all** - Look for card names everywhere in messages: `I'm going to try axe.`\n" + "**none** - Disable automatic card name matching." ); embed.AddField("!a config display {type}", "Select the display type you would like used when an automatic match is found:\n" + "**full** - Display the full card art and the card link.\n" + "**link** - Display mini card art and the card link.\n" + "**image** - Display the full card art, but do not display the card link.\n" + "**mini** - Diplay mini card art and do not display the card link."); embed.AddField("!a config language {type}", "Select the language used for matching and display cards.\n" + "(use `!a config language` for a list - note that not all languages are fully supported)"); embed.AddField("Current Settings", $"match: {guild.LookupSetting}\n" + $"display: {guild.DisplaySetting}\n" + $"language: {guild.Language}"); return(new Tuple <string, Embed>("", embed)); }
public static void Load() { Cache.Clear(); var reader = DatabaseManager.Provider.ExecuteReader("SELECT * FROM guilds"); while (reader.Read()) { var guild = new Models.Guild() { ID = reader.GetInt32("id"), Name = reader.GetString("name"), Emblem = reader.GetString("emblem"), Level = reader.GetInt32("level"), Experience = reader.GetInt64("exp"), Capital = reader.GetInt32("capital"), Spells = reader.GetString("spells"), Stats = reader.GetString("stats"), PerceptorMaxCount = reader.GetInt32("maxperco"), }; Cache.Add(guild.ID, guild); } reader.Close(); Logger.Info("Loaded @'" + Cache.Count + "'@ Guilds"); }
private async Task MessageReceived(SocketMessage rawMessage) { // Ignore system messages and messages from bots if (!(rawMessage is SocketUserMessage message)) { return; } if (message.Source != MessageSource.User) { return; } int argPos = -1; if (!message.HasMentionPrefix(_discord.CurrentUser, ref argPos)) { if (message.Channel is SocketGuildChannel messageGuildChannel) { // check server prefix Models.Guild guildSettings = await _database.FindOneAsync <Models.Guild>(g => g.Id == messageGuildChannel.Guild.Id).ConfigureAwait(false); // intentional empty statement if (guildSettings?.Prefix != null) { if (!message.HasStringPrefix(guildSettings.Prefix, ref argPos)) { argPos = -1; } } } else if (message.Channel is SocketDMChannel) { // try it with no prefix argPos = 0; } } if (argPos == -1) { return; } var context = new SocketCommandContext(_discord, message); var result = await _commands.ExecuteAsync(context, argPos, _provider).ConfigureAwait(false); if (result.Error.HasValue && result.Error.Value == CommandError.UnknownCommand) { return; } else if (!result.IsSuccess) { await context.Channel.SendMessageAsync(string.Empty, embed : new EmbedBuilder() .WithColor(Color.Red) .WithTitle("Error Executing Command" + (result.Error.HasValue ? ": " + ((result.Error.Value == CommandError.Exception && result is ExecuteResult ? new Nullable <ExecuteResult>((ExecuteResult)result) : null)?.Exception?.GetType()?.Name ?? result.Error.Value.ToString()).ToStringCamelCaseToSpace() : string.Empty)) .WithDescription(result.ErrorReason ?? "An unknown error occurred.") .WithTimestamp(message.CreatedAt)).ConfigureAwait(false); } }
public async Task RemoveAsync() { using (var context = Database.OpenContext <Guild>(true)) { Models.Guild guildSettings = await Guild.OpenWriteGuildSettingsAsync(context, Context.Guild.Id).ConfigureAwait(false); guildSettings.Prefix = null; await context.WriteAsync().ConfigureAwait(false); } await ReplyAsync("Removed prefix for this guild. Use an @mention to invoke commands.").ConfigureAwait(false); }
public async Task SetPrefixAsync([Summary("The new prefix for this guild.")] string newPrefix) { using (var context = Database.OpenContext <Guild>(true)) { Models.Guild guildSettings = await Guild.OpenWriteGuildSettingsAsync(context, Context.Guild.Id).ConfigureAwait(false); guildSettings.Prefix = newPrefix; await context.WriteAsync().ConfigureAwait(false); } await ReplyAsync($"Prefix updated to `{newPrefix}` for this guild.").ConfigureAwait(false); }
public static Models.Guild Perform(SocketGuild guild, DataBase db) { var dbGuild = db.Guilds.FirstOrDefault(u => u.DiscordId == guild.Id.ToString()); if (dbGuild == null) { dbGuild = new Models.Guild { DiscordId = guild.Id.ToString() }; db.Guilds.Add(dbGuild); db.SaveChanges(); } return dbGuild; }
public ActionResult Create(Models.Guild _guild) { try { Dominio.DTO.Guild guildDTO = new Dominio.DTO.Guild(); guildDTO.NomeGuild = _guild.NomeGuild; guildDTO.DescricaoGuild = _guild.DescricaoGuild; _guildRepository.Incluid(guildDTO); Created("Guild/Create", guildDTO); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public ActionResult Edit(int id, Models.Guild _guild) { try { Dominio.DTO.Guild guildDTO = new Dominio.DTO.Guild(); guildDTO.IdGuild = id; guildDTO.NomeGuild = _guild.NomeGuild; guildDTO.DescricaoGuild = _guild.DescricaoGuild; _guildRepository.Update(guildDTO); Created("Guild/Edit", guildDTO); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public async Task ListTeamsAsync([Summary("The channel to list teams for. Defaults to the current channel.")] ITextChannel channel = null) { // guaranteed guild context channel = channel ?? (Context.Channel as ITextChannel); Models.Guild guildSettings = await Database.FindOneAsync <Models.Guild>(g => g.Id == Context.Guild.Id).ConfigureAwait(false); if (guildSettings == null || !guildSettings.ChannelSettings.TryGetValue(channel.Id, out Models.Channel channelSettings) || channelSettings?.MonitoredTeams == null || channelSettings.MonitoredTeams.Count == 0) { await ReplyAsync($"{channel.Mention} is not monitoring any teams.").ConfigureAwait(false); } else { var retVal = new StringBuilder(); retVal.AppendLine($"{channel.Mention} is monitoring {Utilities.Pluralize("team", channelSettings.MonitoredTeams.Count)}"); foreach (var teamId in channelSettings.MonitoredTeams) { retVal.AppendLine(teamId.ToString()); } await ReplyAsync(retVal.ToString()).ConfigureAwait(false); } }
async Task TeamPlacementChangeNotificationTimer(TimerStateWrapper state) { try { using (var databaseContext = _database.OpenContext <Models.Guild>(false)) using (var guildSettingEnumerator = databaseContext.FindAllAsync().GetEnumerator()) { CompleteScoreboardSummary masterScoreboard = null; Dictionary <TeamId, int> teamIdsToPeerIndexes = new Dictionary <TeamId, int>(); while (await guildSettingEnumerator.MoveNext().ConfigureAwait(false)) { Models.Guild guildSettings = guildSettingEnumerator.Current; if (guildSettings?.ChannelSettings == null || guildSettings.ChannelSettings.Count == 0) { return; } IGuild guild = _discord.GetGuild(guildSettings.Id); foreach (var chanSettings in guildSettings.ChannelSettings.Values) { if (chanSettings?.MonitoredTeams == null || chanSettings.MonitoredTeams.Count == 0) { continue; } IGuildChannel rawChan = await guild.GetChannelAsync(chanSettings.Id).ConfigureAwait(false); if (!(rawChan is ITextChannel chan)) { continue; } masterScoreboard = await _scoreRetriever.GetScoreboardAsync(ScoreboardFilterInfo.NoFilter).ConfigureAwait(false); foreach (TeamId monitored in chanSettings.MonitoredTeams) { int masterScoreboardIndex = masterScoreboard.TeamList.IndexOfWhere(scoreEntry => scoreEntry.TeamId == monitored); if (masterScoreboardIndex == -1) { continue; } // TODO efficiency: we're refiltering every loop iteration ScoreboardSummaryEntry monitoredEntry = masterScoreboard.TeamList[masterScoreboardIndex]; int peerIndex = masterScoreboard.Clone().WithFilter(_competitionLogic.GetPeerFilter(_scoreRetriever.Round, monitoredEntry)).TeamList.IndexOf(monitoredEntry); teamIdsToPeerIndexes[monitored] = peerIndex; // we've obtained all information, now compare to past data if (state.PreviousTeamListIndexes != null && state.PreviousTeamListIndexes.TryGetValue(monitored, out int prevPeerIndex)) { int indexDifference = peerIndex - prevPeerIndex; if (indexDifference != 0) { StringBuilder announceMessage = new StringBuilder(); announceMessage.Append("**"); announceMessage.Append(monitored); announceMessage.Append("**"); if (indexDifference > 0) { announceMessage.Append(" rose "); } else { announceMessage.Append(" fell "); indexDifference *= -1; } var teamDetails = await _scoreRetriever.GetDetailsAsync(monitored).ConfigureAwait(false); announceMessage.Append(Utilities.Pluralize("place", indexDifference)); announceMessage.Append(" to **"); announceMessage.Append(Utilities.AppendOrdinalSuffix(peerIndex + 1)); announceMessage.Append(" place**."); await chan.SendMessageAsync( announceMessage.ToString(), embed : _messageBuilder .CreateTeamDetailsEmbed( teamDetails, masterScoreboard, _competitionLogic.GetPeerFilter(_scoreRetriever.Round, teamDetails.Summary)) .Build()).ConfigureAwait(false); } } } } } state.PreviousTeamListIndexes = teamIdsToPeerIndexes; } } catch (Exception ex) { await _logService.LogApplicationMessageAsync(LogSeverity.Error, "Error in team monitor timer task", ex).ConfigureAwait(false); } }
private async Task MessageReceived(SocketMessage rawMessage) { // Ignore system messages and messages from bots if (!(rawMessage is SocketUserMessage message)) { return; } if (message.Source != MessageSource.User) { return; } int argPos = -1; if (!message.HasMentionPrefix(_discord.CurrentUser, ref argPos)) { if (message.Channel is SocketGuildChannel messageGuildChannel) { // check server prefix Models.Guild guildSettings = await _database.FindOneAsync <Models.Guild>(g => g.Id == messageGuildChannel.Guild.Id).ConfigureAwait(false); // intentional empty statement if (guildSettings?.Prefix != null) { if (!message.HasStringPrefix(guildSettings.Prefix, ref argPos)) { argPos = -1; } } } else if (message.Channel is SocketDMChannel) { // try it with no prefix argPos = 0; } } if (argPos == -1) { return; } var context = new SocketCommandContext(_discord, message); // don't block the gateway with command executions // since we're using continuewith we don't care to await this call #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed _commands.ExecuteAsync(context, argPos, _provider) .ContinueWith(async x => { IResult result = null; if (x.IsCompletedSuccessfully) { result = x.Result; } if (result != null && result.Error.HasValue && result.Error.Value == CommandError.UnknownCommand) { return; } else if (result == null || !result.IsSuccess) { await context.Channel.SendMessageAsync(string.Empty, embed: new EmbedBuilder() .WithColor(Color.Red) .WithTitle("Error Executing Command" + (result?.Error != null ? ": " + ((result.Error.Value == CommandError.Exception && result is ExecuteResult ? new ExecuteResult?((ExecuteResult)result) : null)?.Exception?.GetType()?.Name ?? (result?.Error.Value.ToString() ?? "Internal Command Execution Error")).ToStringCamelCaseToSpace() : string.Empty)) .WithDescription(result?.ErrorReason ?? "An unknown error occurred.") .WithTimestamp(message.CreatedAt).Build()).ConfigureAwait(false); } }); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed }