private Func <Task> getRegisterUserAction(CommandContext ctx) { return(new Func <Task>(async() => { var discordId = ctx.User.Id.ToString(); var serverId = ctx.Guild.Id.ToString(); var users = UserDbService.GetUsers(); var servers = ServerDbService.GetServers(users); var server = servers[serverId]; var config = LeagueConfigDbService.GetLeagueConfig(server.LeagueConfigId); if (!users.ContainsKey(discordId)) { UserDbService.CreateUser(discordId, serverId, config); } if (!server.Users.Select(x => x.Id).Contains(discordId)) { ServerDbService.AddUserToServer(discordId, serverId, false, false); } else { throw new Exception("You are already registered in this server"); } ulong roleId = Convert.ToUInt64(server.LeagueRoleId); if (!ctx.Guild.Roles.ContainsKey(roleId)) { throw new Exception("Error: League role not found"); } await ctx.Member.GrantRoleAsync(ctx.Guild.Roles[roleId], "registering for riichi league"); await ctx.RespondAsync($"<@{ctx.User.Id}> has been registered"); })); }
private Func <Task> getDisplayLeagueConfigAction(CommandContext ctx, string inputServerId) { return(new Func <Task>(async() => { var serverId = inputServerId; if (serverId == null && ctx.Guild == null) { return; } if (serverId == null) { serverId = ctx.Guild.Id.ToString(); } var userId = ctx.User.Id.ToString(); var allUsers = UserDbService.GetUsers(); if (!allUsers.ContainsKey(userId)) { throw new Exception("You not registered in any server"); } var allServers = ServerDbService.GetServers(allUsers); if (!allServers.ContainsKey(serverId)) { throw new Exception($"Server with id {serverId} does not exist"); } var server = allServers[serverId]; var configId = server.LeagueConfigId; var config = LeagueConfigDbService.GetLeagueConfig(configId); var sb = new StringBuilder(); sb.AppendLine($"countPoints: {(config.CountPoints ? "Yes" : "No")}"); sb.AppendLine($"startingPoints: {config.StartingPoints}"); sb.AppendLine($"allowSanma: {(config.AllowSanma ? "Yes" : "No")}"); sb.AppendLine($"uma3p1: {config.Uma3p1}"); sb.AppendLine($"uma3p2: {config.Uma3p2}"); sb.AppendLine($"uma3p3: {config.Uma3p3}"); sb.AppendLine($"uma4p1: {config.Uma4p1}"); sb.AppendLine($"uma4p2: {config.Uma4p2}"); sb.AppendLine($"uma4p3: {config.Uma4p3}"); sb.AppendLine($"uma4p4: {config.Uma4p4}"); sb.AppendLine($"oka: {config.Oka}"); sb.AppendLine($"penaltyLast: {config.PenaltyLast}"); sb.AppendLine($"useEloSystem: {(config.UseEloSystem? "Yes" : "No")}"); sb.AppendLine($"initialElo: {config.InitialElo}"); sb.AppendLine($"minElo: {config.MinElo}"); sb.AppendLine($"baseEloChangeDampening: {config.BaseEloChangeDampening}"); sb.AppendLine($"eloChangeStartRatio: {config.EloChangeStartRatio}"); sb.AppendLine($"eloChangeEndRatio: {config.EloChangeEndRatio}"); sb.AppendLine($"trialPeriodDuration: {config.TrialPeriodDuration}"); if (ctx.Member != null) { await ctx.Member.SendMessageAsync(sb.ToString()); } else { await ctx.RespondAsync(sb.ToString()); } })); }
private Func <Task> getRegisterUserAction(CommandContext ctx) { return(new Func <Task>(async() => { var discordId = ctx.User.Id.ToString(); var serverDiscordId = ctx.Guild.Id.ToString(); var server = ServerDbService.GetServer(serverDiscordId); var config = LeagueConfigDbService.GetLeagueConfig(server.LeagueConfigId); UserDbService.CreateUser(discordId, serverDiscordId, config); ServerDbService.AddUserToServer(discordId, serverDiscordId, false, false); ulong roleId = Convert.ToUInt64(server.LeagueRoleId); if (!ctx.Guild.Roles.ContainsKey(roleId)) { throw new Exception("Error: League role not found"); } await ctx.Member.GrantRoleAsync(ctx.Guild.Roles[roleId], "registering for riichi league"); await ctx.RespondAsync($"<@{ctx.User.Id}> has been registered"); })); }
private Func <Task> getRegisterDummyAction(CommandContext ctx) { return(new Func <Task>(async() => { var discordId = ctx.User.Id.ToString(); var serverDiscordId = ctx.Guild.Id.ToString(); var server = ServerDbService.GetServer(serverDiscordId); var config = LeagueConfigDbService.GetLeagueConfig(server.LeagueConfigId); var heatiro = "323096688904634377"; var clubapero = "198974501709414401"; var Neral = "273192430172372993"; UserDbService.CreateUser(heatiro, serverDiscordId, config); UserDbService.CreateUser(clubapero, serverDiscordId, config); UserDbService.CreateUser(Neral, serverDiscordId, config); ServerDbService.AddUserToServer(heatiro, serverDiscordId, false, false); //Heatiro ServerDbService.AddUserToServer(clubapero, serverDiscordId, false, false); //clubapero ServerDbService.AddUserToServer(Neral, serverDiscordId, false, false); //Neral UserDbService.SetMahjsoulName(heatiro, "heairo"); UserDbService.SetMahjsoulName(Neral, "Neral"); UserDbService.SetMahjsoulName(clubapero, "clubapero"); await Task.FromResult(false); })); }
public async static Task OnPendingGameReaction(DiscordClient sender, DiscordMessage msg, DiscordEmoji emoji, DiscordUser user, bool added) { var kanContext = KandoraContext.Instance; var msgId = msg.Id; var userId = user.Id.ToString(); var game = kanContext.PendingGames[msgId]; bool result = false; var okEmoji = DiscordEmoji.FromName(sender, Reactions.OK); var noEmoji = DiscordEmoji.FromName(sender, Reactions.NO); if (emoji.Id == okEmoji.Id) { result = game.TryChangeUserOk(userId, isAdd: added); } else if (emoji.Id == noEmoji.Id) { result = game.TryChangeUserNo(userId, isAdd: added); } if (!result && added) { await msg.DeleteReactionAsync(emoji, user); } if (game.IsCancelled) { await msg.ModifyAsync($"All players have voted {noEmoji}, this log won't be recorded"); kanContext.PendingGames.Remove(msgId); } if (game.IsValidated) { DbService.Begin("recordgame"); try { var serverId = msg.Channel.GuildId.ToString(); var users = UserDbService.GetUsers(); var servers = ServerDbService.GetServers(users); var server = servers[serverId]; var leagueConfig = LeagueConfigDbService.GetLeagueConfig(server.LeagueConfigId); if (game.Log == null) { ScoreDbService.RecordIRLGame(game.UserIds, game.Scores, server, leagueConfig); } else { ScoreDbService.RecordOnlineGame(game.Log, server); } kanContext.PendingGames.Remove(msgId); await msg.RespondAsync($"All players have voted {okEmoji}, this log has been recorded!"); await msg.DeleteReactionsEmojiAsync(okEmoji); await msg.DeleteReactionsEmojiAsync(noEmoji); DbService.Commit("recordgame"); } catch (Exception e) { DbService.Rollback("recordgame"); await msg.RespondAsync(e.Message); } } }