Esempio n. 1
0
            private async Task Prepare()
            {
                await _localization.Load(await _language.GetLanguage(Context.Guild.Id));

                _data = await _channel.Load(Context.Guild.Id, AutomationType.Temporary);
            }
Esempio n. 2
0
        private async Task JoinChannel(SocketVoiceChannel channel, SocketGuildUser user)
        {
            if (channel == null)
            {
                return;
            }

            var failed = false;
            RestVoiceChannel newChannel = null;

            try
            {
                var auto = await _channel.Load(channel.Guild.Id, AutomationType.Temporary);

                if (channel.Name.StartsWith(auto.Prefix, StringComparison.OrdinalIgnoreCase))
                {
                    newChannel = await DuplicateChannel(channel, user, auto.Name);

                    await _channel.AddGeneratedChannel(channel.Guild.Id, newChannel.Id);

                    _channels.Remove(newChannel.Id);
                    return;
                }

                var perma = await _channel.Load(channel.Guild.Id, AutomationType.Permanent);

                if (channel.Name.StartsWith(perma.Prefix, StringComparison.OrdinalIgnoreCase))
                {
                    newChannel = await DuplicateChannel(channel, user, perma.Name);

                    _channels.Remove(newChannel.Id);
                }
            }
            catch (HttpException httpException)
            {
                if (!httpException.Message.Contains("error 50013: Missing Permissions"))
                {
                    await Logs.Write("Crashes",
                                     $"JoinChannel crashed. ({channel.Guild.Id}) {channel.Id}, {channel.Name}.", httpException);
                }
                else
                {
                    var pmChannel = await channel.Guild.Owner.GetOrCreateDMChannelAsync();
                    await LoadLanguage(channel.Guild.Id);

                    await pmChannel.SendMessageAsync(_localization.GetMessage("Channel no permission",
                                                                              channel.Guild.Name, channel.Name));
                }

                failed = true;
            }
            catch (Exception e)
            {
                await Logs.Write("Crashes",
                                 $"JoinChannel crashed. ({channel.Guild.Id}) {channel.Id}, {channel.Name}.", e);

                failed = true;
            }

            if (failed)
            {
                if (newChannel != null)
                {
                    await newChannel.DeleteAsync();

                    try
                    {
                        await _channel.RemoveGeneratedChannel(newChannel.GuildId, newChannel.Id);
                    }
                    catch (Exception)
                    {
                        //ignore
                    }

                    _channels.Remove(newChannel.Id);
                }
            }
        }