Exemple #1
0
        public async Task ServerInfoAsync(ulong?guid = null)
        {
            if (guid == null)
            {
                guid = this.Context.Guild.Id;
            }
            var info = await DynamoSystem.GetItemAsync <GuildInfo>(guid.ToString()).ConfigureAwait(false);

            Embed embed;

            if (info == null || string.IsNullOrEmpty(info.GuildGuid))
            {
                embed = EmbedHandler.GenerateEmbedResponse(
                    "No Server was found with that GUID",
                    Color.Orange);
            }
            else
            {
                embed = EmbedHandler.GenerateEmbedResponse(
                    $"GuildGuid: {info.GuildGuid}\r\n" +
                    $"GuildName: {info.GuildName}");
            }

            await this.ReplyAsync("", false, embed).ConfigureAwait(false);
        }
Exemple #2
0
        private async Task OnGuildUpdate(SocketGuild arg1, SocketGuild arg2)
        {
            var guildInfo = await DynamoSystem.GetItemAsync <GuildInfo>(arg1.Id);

            guildInfo.GuildName = arg2.Name;

            await DynamoSystem.UpdateItemAsync(guildInfo);
        }
Exemple #3
0
        private static async Task OnLeftGuildAsync([NotNull] SocketGuild arg)
        {
            var guild = await DynamoSystem.GetItemAsync <GuildInfo>(arg.Id).ConfigureAwait(false);

            if (guild == null)
            {
                return;
            }

            await DynamoSystem.DeleteItemAsync(guild).ConfigureAwait(false);
        }
Exemple #4
0
        private static async Task OnGuildUpdatedAsync([NotNull] SocketGuild arg1, [NotNull] SocketGuild arg2)
        {
            var origGuildId = arg1.Id;
            var guild       = await DynamoSystem.GetItemAsync <GuildInfo>(origGuildId).ConfigureAwait(false);

            if (guild != null)
            {
                guild.GuildGuid = arg2.Id.ToString();
                guild.GuildName = arg2.Name;
                await DynamoSystem.UpdateItemAsync(guild).ConfigureAwait(false);
            }
        }
        public static async Task HandleChannelPair([NotNull] SocketUser user, SocketVoiceState oldVoiceState,
                                                   SocketVoiceState newVoiceState, DiscordSocketClient discord)
        {
            var oldGuild = oldVoiceState.VoiceChannel?.Guild;
            var newGuild = newVoiceState.VoiceChannel?.Guild;

            var oldChannelGuid = oldVoiceState.VoiceChannel == null ? string.Empty : oldVoiceState.VoiceChannel.Id.ToString();
            var newChannelGuid = newVoiceState.VoiceChannel == null ? string.Empty : newVoiceState.VoiceChannel.Id.ToString();

            var oldPair = string.IsNullOrEmpty(oldChannelGuid) ? null : await DynamoSystem.GetItemAsync <ChannelPair>(oldChannelGuid);

            var newPair = string.IsNullOrEmpty(newChannelGuid) ? null : await DynamoSystem.GetItemAsync <ChannelPair>(newChannelGuid);

            if (oldPair == null && newPair == null)
            {
                return;
            }

            var oldGuildUser = oldGuild?.GetUser(user.Id);
            var newGuildUser = newGuild?.GetUser(user.Id);

            if (oldPair != null && oldGuild != null)
            {
                var role = oldGuild?.Roles.SingleOrDefault(x => x.Id.ToString() == oldPair.RoleGuid);
                if (role != null)
                {
                    await oldGuildUser.RemoveRoleAsync(role);
                }
                var embed = EmbedHandler.GenerateEmbedResponse(
                    $"\u274C {user.Username} has left {oldVoiceState.VoiceChannel?.Name}",
                    Color.Red);
                await oldGuild.TextChannels.Single(x => x.Id.ToString() == oldPair.TextChannelGuid)
                .SendMessageAsync("", false, embed);
            }

            if (newPair != null && newGuild != null)
            {
                var role = newGuild?.Roles.SingleOrDefault(x => x.Id.ToString() == newPair.RoleGuid);
                if (role != null)
                {
                    await newGuildUser.AddRoleAsync(role);
                }
                var embed = EmbedHandler.GenerateEmbedResponse(
                    $"\u2705 {user.Username} has joined {newVoiceState.VoiceChannel?.Name}",
                    Color.Green);
                await newGuild.TextChannels.Single(x => x.Id.ToString() == newPair.TextChannelGuid)
                .SendMessageAsync("", false, embed);
            }
        }
Exemple #6
0
        private static async Task OnJoinedGuildAsync([NotNull] SocketGuild arg)
        {
            var guild = await DynamoSystem.GetItemAsync <GuildInfo>(arg.Id).ConfigureAwait(false);

            if (guild != null)
            {
                return;
            }

            guild = new GuildInfo
            {
                GuildGuid = arg.Id.ToString(),
                GuildName = arg.Name
            };

            await DynamoSystem.PutItemAsync(guild).ConfigureAwait(false);
        }