Exemplo n.º 1
0
 public static async Task <IEnumerable <SocketGuild> > GetUserGuildsAsync(
     SocketGuildUser guildUser,
     IDiscordClient client)
 {
     return((await client.GetGuildsAsync())
            .Select(g => g as SocketGuild)
            .Where(g => g.Users.Any(u => u.Id == guildUser.Id)));
 }
Exemplo n.º 2
0
        private async Task SetupAsync(IDiscordClient client)
        {
            this._client = client;

            foreach (var server in await client.GetGuildsAsync())
            {
                timedoutUsers.Add(server.Id, new List<TimedoutUser>());
            }
        }
Exemplo n.º 3
0
        public static async Task <IReadOnlyCollection <IUser> > GetGuildUsersAsync(this IDiscordClient client)
        {
            var list = ImmutableArray.CreateBuilder <IUser>();

            foreach (var guild in await client.GetGuildsAsync())
            {
                list.AddRange(await guild.GetUsersAsync());
            }

            return(list.ToImmutable());
        }
Exemplo n.º 4
0
        public virtual async Task RunAsync()
        {
            if (DateTime.Now > lastTimeUpdated + updateTime)
            {
                await api.UpdateStats(
                    (await client.GetGuildsAsync()).Count
                    );

                lastTimeUpdated = DateTime.Now;
                SendLog("Submitted stats to Top.gg!");
            }
        }
Exemplo n.º 5
0
        public async Task Stats(SocketCommandContext context, string[] command, ServerConfig serverConfig)
        {
            var guilds = await discordClient.GetGuildsAsync();

            var builder = new StringBuilder();

            builder.Append("Uptime: ");
            builder.Append(GetUptimeString());
            builder.AppendLine();
            builder.Append("Messages Seen: ");
            builder.Append(statsService.GetSeenMessages());
            builder.AppendLine();
            builder.Append("Server Count: ");
            builder.Append(guilds.Count);
            await context.Reply(builder.ToString());
        }
Exemplo n.º 6
0
        public async void LoadGuildInformation(IDiscordClient client)
        {
            var guilds = await client.GetGuildsAsync();

            foreach (var guildConfig in Guilds)
            {
                var guild = guilds.FirstOrDefault(g => g.Id == guildConfig.GuildId);
                if (guild != null)
                {
                    foreach (var role in guildConfig.Roles)
                    {
                        role.GuildConfiguration = guildConfig;
                        role.Value = guild.GetRole(role.RoleId);
                    }
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Returns the mutual guilds of a <see cref="IGuildUser"/>
        /// </summary>
        public static async Task <IReadOnlyCollection <IGuild> > GetMutualGuildsAsync(this IUser user,
                                                                                      IDiscordClient client)
        {
            if (user is SocketUser socketUser)
            {
                return(socketUser.MutualGuilds);
            }

            var guilds = await client.GetGuildsAsync();

            var result = new List <IGuild>(1);

            foreach (IGuild guild in guilds)
            {
                if (await guild.GetUserAsync(user.Id) != null)
                {
                    result.Add(guild);
                }
            }
            return(result.AsReadOnly());
        }
Exemplo n.º 8
0
        public async Task SendMessageToDefaultChannelAsync(string message)
        {
            try
            {
                var guilds = await _client.GetGuildsAsync();

                var chans = await guilds
                            .First(x => x.Id == BotSettings.Instance.DefaultGuild)
                            .GetTextChannelsAsync();

                var channel = chans.First(x => x.Id == BotSettings.Instance.DefaultChannel);
                await channel.SendMessageAsync(message);
            }
            catch (NullReferenceException)
            {
                Log.Error("Could not send message to default channel since it has not been set or was not found.");
            }
            catch (Exception)
            {
                Log.Error($"Couldn't send message because channel '{BotSettings.Instance.DefaultChannel}' at '{BotSettings.Instance.DefaultGuild}' not found.");
            }
        }