Exemplo n.º 1
0
        public static async Task<bool> CanJoinAndTalkInVoiceChannel(Channel voiceChannel, Channel callback)
        {
            if (voiceChannel.Type != ChannelType.Voice) throw new ArgumentException(nameof(voiceChannel));
            if (callback.Type != ChannelType.Text) throw new ArgumentException(nameof(callback));

            if (!voiceChannel.Server.CurrentUser.GetPermissions(voiceChannel).Speak)
            {
                await callback.SafeSendMessage($"I don't have permission to speak in `{voiceChannel.Name}`.");
                return false;
            }
            if (!voiceChannel.CanJoinChannel(voiceChannel.Server.CurrentUser))
            {
                await callback.SafeSendMessage($"I don't have permission to join `{voiceChannel.Name}`");
                return false;
            }

            return true;
        }
Exemplo n.º 2
0
        public static async Task JoinInvite(string inviteId, Channel callback)
        {
            Invite invite = await callback.Client.GetInvite(inviteId);
            if (invite == null)
            {
                await callback.SafeSendMessage("Invite not found.");
                return;
            }
            if (invite.IsRevoked)
            {
                await
                    callback.SafeSendMessage("This invite has expired or the bot is banned from that server.");
                return;
            }

            await invite.Accept();
            await callback.SafeSendMessage("Joined server.");
            await Config.Owner.SendPrivate($"Joined server: `{invite.Server.Name}`.");
        }
Exemplo n.º 3
0
        private async Task<ModuleManager> VerifyFindModule(string id, Channel callback, bool useCallback = true)
        {
            ModuleManager module = GetModule(id);
            if (module == null)
            {
                if (useCallback)
                    await callback.SafeSendMessage("Unknown module");
                return null;
            }

            if (module.FilterType == ModuleFilter.None ||
                module.FilterType == ModuleFilter.AlwaysAllowPrivate)
            {
                if (useCallback)
                    await callback.SafeSendMessage("This module is global and cannot be enabled/disabled.");
                return null;
            }

            return module;
        }
Exemplo n.º 4
0
        private async Task RemoveAutoRoleAssigner(ulong serverId, Channel callback, bool shouldCallback = true)
        {
            ulong ignored;
            _joinedRoleSubs.TryRemove(serverId, out ignored);

            if (shouldCallback)
                await callback.SafeSendMessage("Removed auto role assigner for this server.");
        }
Exemplo n.º 5
0
        private async Task PrintUserInfo(User user, Channel textChannel)
        {
            if (user == null)
            {
                await textChannel.SafeSendMessage("User not found.");
                return;
            }

            StringBuilder builder = new StringBuilder("**User info:\r\n**```");
            builder.AppendLine($"- Name: {user.Name} ({user.Discriminator})");
            builder.AppendLine($"- Id: {user.Id}");
            builder.AppendLine($"- Avatar: {user.AvatarUrl}");
            builder.AppendLine($"- Joined: {user.JoinedAt} ");
            await textChannel.SafeSendMessage($"{builder}```");
        }
Exemplo n.º 6
0
        private async Task Subscribe(string twitchChannel, Channel discordChannel)
        {
            if (!_twitch.IsConnected)
                await TwitchTryConnect();

            // normalize channel name.
            twitchChannel = TwitchBot.NormalizeChannelName(twitchChannel);

            // if the twitch bot is not in the twitch channel, tell it to join it.
            if (!_twitch.Channels.Contains(twitchChannel))
                _twitch.JoinChannel(twitchChannel);

            // if there is no entry in _relays for the twitch channel, create one.
            if (!_relays.ContainsKey(twitchChannel))
            {
                List<JsonChannel> channel = new List<JsonChannel> {discordChannel};
                _relays.Add(twitchChannel, channel);
                return;
            }

            // reference the list of channels found by the twitch channel key so we dont have to look it up every time.
            List<JsonChannel> subRef = _relays[twitchChannel];

            // check if the discord channel is already subscribed to the twitch channel.
            if (subRef.FirstOrDefault(c => c.Channel.Id == discordChannel.Id) != null)
                return;

            // add the discord channel to the twitch channel subscribers list.
            subRef.Add(discordChannel);

            await discordChannel.SafeSendMessage($"Subscribed to twitch chat: {twitchChannel}");
        }
Exemplo n.º 7
0
        private async Task Unsubscribe(string twitchChannel, Channel discordChannel)
        {
            // normalize channel name.
            twitchChannel = TwitchBot.NormalizeChannelName(twitchChannel);

            // dont try to remove from a list of subscribers in a twitch channel if we dont even have the channel in the relays list.
            if (!_relays.ContainsKey(twitchChannel)) return;

            // if the twitch relay discord connected channel list doesn't include the discord channel that
            // is passed as the argument, return. We don't want to try to delete something that doesn't exist.
            if (_relays[twitchChannel].FirstOrDefault(c => c.Channel.Id == discordChannel.Id) == null) return;

            // Remove all of the channels in the twitchChannel entry which have the same id as the
            // discord channel that we passed in the arguments
            _relays[twitchChannel].RemoveAll(match => match.Channel.Id == discordChannel.Id);

            // we will command the twitch bot to disconnect from the twitch channel if no
            // discord channel is connected to it.
            if (!_relays[twitchChannel].Any())
                _twitch.PartChannel(twitchChannel);

            await discordChannel.SafeSendMessage($"Unsubscribed from twitch chat: {twitchChannel}");
        }
Exemplo n.º 8
0
        /// <summary>
        ///     Attempts to join a voice channel.
        /// </summary>
        /// <param name="textCallback">Text callback channel to which we will write when we failed joining the audio channel.</param>
        /// <returns>Null if failed joining.</returns>
        public static async Task<IAudioClient> SafeJoin(this AudioService audio, Channel voiceChannel,
            Channel textCallback)
        {
            if (voiceChannel.Type != ChannelType.Voice) throw new ArgumentException(nameof(voiceChannel));
            if (textCallback.Type != ChannelType.Text) throw new ArgumentException(nameof(textCallback));

            if (voiceChannel.CanJoinChannel(voiceChannel.Server.CurrentUser))
            {
                try
                {
                    return await audio.Join(voiceChannel);
                }
                catch
                {
                    await textCallback.SafeSendMessage($"Failed joining voice channel `{voiceChannel.Name}`.");
                }
            }

            await textCallback.SafeSendMessage($"I don't have permission to join `{voiceChannel.Name}`.");
            return null;
        }