Пример #1
0
        public static string FormatDateTime(ConfigGuild guild, string str)
        {
            var zdt  = Instant.FromDateTimeUtc(DateTime.UtcNow).InZone(guild.TimeZone);
            var info = DateTimeFormatInfo.CurrentInfo;

            return(str.Replace("{{.Date}}", zdt.ToString(info.LongDatePattern, null))
                   .Replace("{{.DateTime}}", zdt.ToString(info.FullDateTimePattern, null))
                   .Replace("{{.Time}}", zdt.ToString(info.LongTimePattern, null)));
        }
Пример #2
0
 public CWBContext(CWBDrone bot, IUserMessage message)
 {
     Client = bot.Socket;
     Channel = message.Channel;
     TextChannel = message.Channel as ITextChannel;
     Guild = TextChannel?.Guild;
     User = message.Author;
     GuildUser = User as IGuildUser;
     ConfigGuild = Guild != null ? bot.Configuration.Guilds.GetGuild(Guild.Id) : null;
     Bot = bot;
     Message = message;
     Prefix = ConfigGuild?.Prefix ?? CWBDrone.Prefix;
 }
Пример #3
0
        public async Task GrantRoleAsync(string speedruncomName)
        {
            ConfigGuild confGuild = Context.Bot.Config.GetOrAddGuild(Context.GuildId);

            if (confGuild.SpeedrunnerRole == default || confGuild.SpeedrunnerGames.Count == 0)
            {
                await Response("Speedrun system not setup, an admin will have to provide a role id and game list");

                return;
            }

            User user = await User.FindById(speedruncomName);

            if (user == null)
            {
                await Response("User not found");

                return;
            }

            string discord = await user.GetDiscordAsync();

            if (discord?.ToLower() != $"{Context.Author.Name.ToLower()}#{Context.Author.Discriminator}")
            {
                await Response("Please ensure your discord account is linked on your speedrun.com profile");

                return;
            }

            foreach (string gameId in confGuild.SpeedrunnerGames)
            {
                Game game = await Game.Find(gameId);

                if (game == null)
                {
                    return;
                }

                // Only really have to check if any run exists, but not sure how to do this aside from await foreach
                await foreach (Run _ in game.GetRunsAsync(RunStatus.Verified, user.Id))
                {
                    await Context.Author.GrantRoleAsync(confGuild.SpeedrunnerRole);
                    await Response("Role granted");

                    return;
                }
            }

            await Response("No verified runs found");
        }
Пример #4
0
        public async Task ListPermissionsAsync()
        {
            ConfigGuild guild = Context.Bot.Config.GetOrAddGuild(Context.Guild.Id);

            Dictionary <string, List <string> > mentionDict = new();

            foreach ((ulong userId, ConcurrentSet <string> perms) in guild.UserPermOverrides)
            {
                foreach (string perm in perms)
                {
                    if (!mentionDict.TryGetValue(perm, out List <string> mentions))
                    {
                        mentions          = new();
                        mentionDict[perm] = mentions;
                    }

                    mentions.Add($"<@{userId}>");
                }
            }

            foreach ((ulong roleId, ConcurrentSet <string> perms) in guild.RolePermOverrides)
            {
                foreach (string perm in perms)
                {
                    if (!mentionDict.TryGetValue(perm, out List <string> mentions))
                    {
                        mentions          = new();
                        mentionDict[perm] = mentions;
                    }

                    mentions.Add($"<@&{roleId}>");
                }
            }

            LocalEmbedBuilder embed = new() { Title = "Permission overrides" };

            foreach ((string perm, List <string> mentions) in mentionDict)
            {
                embed.AddField(perm, string.Join(", ", mentions));
            }

            await Response(embed);
        }
Пример #5
0
        public async Task RemoveGameAsync(string gameName)
        {
            Game game = await Game.Find(gameName);

            if (game == null)
            {
                await Response("Couldn't locate game, please supply a valid speedrun.com url or game id");

                return;
            }

            ConfigGuild confGuild = Context.Bot.Config.GetOrAddGuild(Context.Guild.Id);

            ConcurrentSet <string> trackedGames = confGuild.GetOrAddGameList(Context.Channel.Id);

            if (!trackedGames.Contains(game.Id))
            {
                await Response($"Game '{game.Name}' is not being tracked in this channel");

                return;
            }

            ConcurrentDictionary <string, ConfigRun> runMessages = confGuild.GetOrAddChannel(Context.ChannelId).RunMessages;

            foreach ((string runId, ConfigRun run) in runMessages)
            {
                IMessage msg = await Context.Bot.GetMessageAsync(Context.ChannelId, run.MsgId);

                if (msg?.Author?.Id != Context.Bot.CurrentUser.Id)
                {
                    continue;
                }

                await msg.DeleteAsync();

                runMessages.Remove(runId, out _);
            }

            trackedGames.Remove(game.Id);
            await Response($"No longer tracking game '{game.Name}' in this channel");
        }
        public static bool UserHasPermission(VCommandContext context)
        {
            ConfigGuild guild = context.Bot.Config.GetOrAddGuild(context.Guild.Id);

            // Check user perms
            ConcurrentSet <string> perms = guild.GetOrAddUserPerms(context.Author.Id);

            if (perms.Contains(context.Command.Module.Name) || perms.Contains(context.Command.Name))
            {
                return(true);
            }

            // Check role perms
            foreach (ulong roleId in context.Author.RoleIds)
            {
                perms = guild.GetOrAddRolePerms(roleId);
                if (perms.Contains(context.Command.Module.Name) || perms.Contains(context.Command.Name))
                {
                    return(true);
                }
            }

            return(false);
        }