Exemplo n.º 1
0
 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");
     }));
 }
Exemplo n.º 2
0
        protected static async Task executeCommand(CommandContext ctx, Func <Task> command, bool userMustBeRegistered = true, bool userMustBeInChannel = true, bool serverMustBeRegistered = true)
        {
            var commandStr = "command";

            try
            {
                if (userMustBeInChannel && (ctx.Channel == null || ctx.Guild == null))
                {
                    throw new Exception("You must be in a text channel for that command.");
                }
                string serverId  = (ctx.Guild.Id.ToString());
                string channelId = (ctx.Channel.Id.ToString());
                string userId    = (ctx.User.Id.ToString());
                Server server    = null;
                if (serverMustBeRegistered || userMustBeInChannel)
                {
                    server = ServerDbService.GetServer(serverId);
                }
                if (userMustBeInChannel && (server == null || server.TargetChannelId != channelId))
                {
                    throw new SilentException();
                }
                if (userMustBeRegistered && !ServerDbService.isUserOnServer(userId, serverId))
                {
                    throw new Exception($"<@{userId}> is not registered yet, use !register to enter the league.");
                }
                DbService.Begin(commandStr);
                await command.Invoke();

                DbService.Commit(commandStr);
            }
            catch (Exception e)
            {
                if (!(e is SilentException))
                {
                    await ctx.RespondAsync(e.Message);
                }
                DbService.Rollback(commandStr);
            }
        }
Exemplo n.º 3
0
 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);
     }));
 }