Example #1
0
        public async Task PermaChannelSetIcon([Remainder] string message)
        {
            var persistence = AutoChannel.Load(Context.Guild.Id);

            if (message.StartsWith(persistence.GetAutoChannelIcon()))
            {
                await ReplyAsync("I am not able to use the same icon for both auto channels and perma channels.");

                return;
            }

            persistence.SetPermaChannelIcon(message);
            persistence.Save();
            await ReplyAsync($"The new perma channel icon for this server is '{persistence.GetPermaChannelIcon()}'");
        }
Example #2
0
        private async Task LeaveChannel(SocketVoiceChannel channel, SocketGuildUser user)
        {
            try
            {
                if (channel == null)
                {
                    return;
                }

                if (channel.Users.Count != 0)
                {
                    if (channel.Users.Count != 1 || !channel.Users.First().Id.Equals(_client.CurrentUser.Id))
                    {
                        return;
                    }
                    var audioService = (AudioService)_services.GetService(typeof(AudioService));
                    audioService.BeforeExecute(channel.Guild.Id);
                    await audioService.TextChannel.SendMessageAsync("Music player was terminated. All users have left the voice channel.");

                    audioService.Stop();
                    return;
                }

                while (_channels.Contains(channel.Id))
                {
                    await Task.Delay(100);
                }

                var autoChannel = AutoChannel.Load(channel.Guild.Id);
                if (!autoChannel.IsControlledChannel(channel.Id))
                {
                    return;
                }
                var userName = user?.Nickname ?? user?.Username ?? "User";
                LogsHandler.Instance.Log("Channels", channel.Guild, $"{userName} left channel '{channel.Name}'.");
                autoChannel.RemoveChannel(channel.Id);
                autoChannel.Save();
                await channel.DeleteAsync();
            }
            catch (Exception e)
            {
                var info = channel == null ? "Null channel" : $"({channel.Guild.Id}) {channel.Id}, {channel.Name}";
                LogsHandler.Instance.Log("Crashes", $"LeaveChannel crashed. {info}. Stacktrace: {e}");
            }
        }
Example #3
0
        private async Task JoinChannel(SocketVoiceChannel channel, SocketGuildUser user)
        {
            try
            {
                if (channel == null || user == null)
                {
                    return;
                }
                var autoChannel = AutoChannel.Load(channel.Guild.Id);
                if (autoChannel.IsPermaChannel(channel))
                {
                    LogsHandler.Instance.Log("Channels", channel.Guild,
                                             $"{user.Username} joined channel '{channel.Name}'.");
                    var nameEnding = user.Username.EndsWith("s", StringComparison.CurrentCultureIgnoreCase)
                        ? "'"
                        : "'s";
                    var channelId = await DuplicateChannel(channel, user, $"{user.Username}{nameEnding} channel");

                    _channels.Remove(channelId);
                }
                else if (autoChannel.IsAutoChannel(channel))
                {
                    LogsHandler.Instance.Log("Channels", channel.Guild,
                                             $"{user.Username} joined channel '{channel.Name}'.");
                    var channelId = await DuplicateChannel(channel, user);

                    autoChannel.AddChannel(channelId);
                    autoChannel.Save();
                    _channels.Remove(channelId);
                }
            }
            catch (Exception e)
            {
                var info = channel == null ? "Null channel" : $"({channel.Guild.Id}) {channel.Id}, {channel.Name}";
                LogsHandler.Instance.Log("Crashes", $"JoinChannel crashed. {info}. Stacktrace: {e}");
            }
        }
Example #4
0
        public async Task DefaultPermaChannel()
        {
            await ReplyAsync(
                $@"The current perma channel icon for this server is '{AutoChannel.Load(Context.Guild.Id).GetPermaChannelIcon()}'.
You can check 'http://unicode.org/emoji/charts/full-emoji-list.html' for the icon to paste in the channel name.");
        }
Example #5
0
 public ChannelAutomation()
 {
     Id           = "ChannelAutomations/";
     AutoChannel  = new AutoChannel();
     PermaChannel = new PermaChannel();
 }
Example #6
0
 public async Task AutoChannelFix()
 {
     AutoChannel.Remove(Context.Guild.Id);
     await ReplyAsync($"Your auto channels should now be fixed. If you had a custom prefix you will need to set this again.");
 }