Beispiel #1
0
        public static async Task LookupAndSendAsync(SocketGuild guild, SocketCommandContext context, string channelName, string message, bool replyable, DataBase db)
        {
            var dbGuild = FindOrCreateGuild.Perform(guild, db);

            if (!UserHasRole.Perform(guild, context.User, dbGuild))
            {
                await context.Channel.SendMessageAsync("You do not have the role required to send messages to this server.");

                return;
            }

            var candidateChannels = guild.TextChannels.Where(x => x.Name.ToLower().Contains(channelName.ToLower()) || x.Id.ToString() == channelName);

            if (!candidateChannels.Any())
            {
                await context.Channel.SendMessageAsync("The channel you specified couldn't be found. Please specify your channel using the following command: `send (channel_name) (message)` ex: `send some-channel you guys suck`");

                return;
            }

            var prefix          = PrefixHelper.ComputePrefix(context, dbGuild);
            var channel         = candidateChannels.OrderBy(x => x.Name.Length).First();
            var messageFunction = Send.SendMessageToChannel(channel, replyable, context.User);

            await messageFunction(prefix, message);

            await Send.SendSentEmote(context);
        }
Beispiel #2
0
        public static async Task LookupAndSendAsync(SocketGuild guild, ShardedCommandContext context, string channelName, string message, bool replyable, DataBase db)
        {
            var dbGuild = FindOrCreateGuild.Perform(guild, db);

            if (!UserHasRole.Perform(guild, context.User, dbGuild))
            {
                await Send.SendErrorWithDeleteReaction(context, "You do not have the role required to send messages to this server.");

                return;
            }

            var candidateChannels = guild.TextChannels.Where(x => x.Name.ToLower().Contains(channelName.ToLower()) || x.Id.ToString() == channelName);

            if (!candidateChannels.Any())
            {
                await Send.SendErrorWithDeleteReaction(context, "The channel you specified couldn't be found. Please specify your channel using the following command: `send (channel_name) (message)` ex: `send some-channel you guys suck`");

                return;
            }

            if (PrefixHelper.UserBlocked(context.User.Id, dbGuild))
            {
                await context.Channel.SendMessageAsync("It appears that you have been banned from using Voltaire on the targeted server. If you think this is an error, contact one of your admins.");

                return;
            }

            if (!IncrementAndCheckMessageLimit.Perform(dbGuild, db))
            {
                await Send.SendErrorWithDeleteReaction(context, "This server has reached its limit of 50 messages for the month. To lift this limit, ask an admin or moderator to upgrade your server to Voltaire Pro.");

                return;
            }

            var prefix          = PrefixHelper.ComputePrefix(context, dbGuild);
            var channel         = candidateChannels.OrderBy(x => x.Name.Length).First();
            var messageFunction = Send.SendMessageToChannel(channel, replyable, context);

            await messageFunction(prefix, message);

            await Send.SendSentEmote(context);

            return;
        }
Beispiel #3
0
        public static async Task PerformAsync(ShardedCommandContext context, string replyKey, string message, bool replyable, DataBase db)
        {
            var candidateGuilds = Send.GuildList(context);

            var key         = LoadConfig.Instance.config["encryptionKey"];
            var candidateId = Rijndael.Decrypt(replyKey, key, KeySize.Aes256);

            // TODO: potentially want to bake guilds into reply codes so we can ensure that the the replier isn't banned on the server where the original
            // message was sent
            var users = SendDirectMessage.ToUserList(candidateGuilds).Where(x => x.Id.ToString() == candidateId);

            if (users.Count() == 0)
            {
                await Send.SendErrorWithDeleteReaction(context, "Something is wrong with that reply code. It is possible the sender has left your server.");

                return;
            }

            var allowedGuild = users.ToList().Select(x => FindOrCreateGuild.Perform(x.Guild, db)).FirstOrDefault(x => !PrefixHelper.UserBlocked(context, x));

            if (allowedGuild == null)
            {
                await context.Channel.SendMessageAsync("It appears that you have been banned from using Voltaire on the targeted server. If you think this is an error, contact one of your admins.");

                return;
            }

            var prefix = $"{PrefixHelper.ComputePrefix(context, allowedGuild, "someone")} replied";

            // all 'users' hera are technically the same user, so just take the first
            var channel = await users.First().GetOrCreateDMChannelAsync();

            var messageFunction = Send.SendMessageToChannel(channel, replyable, context.User);

            await messageFunction(prefix, message);

            await Send.SendSentEmote(context);

            await Send.SendSentEmote(context);
        }
Beispiel #4
0
        public static async Task PerformAsync(SocketCommandContext context, string replyKey, string message, DataBase db)
        {
            var candidateGuilds = Send.GuildList(context);

            var key         = LoadConfig.Instance.config["encryptionKey"];
            var candidateId = Rijndael.Decrypt(replyKey, key, KeySize.Aes256);

            var user = SendDirectMessage.ToUserList(candidateGuilds).Where(x => x.Id.ToString() == candidateId).FirstOrDefault();

            if (user == null)
            {
                await context.Channel.SendMessageAsync("Something is wrong with that reply code. It is possible the sender has left your server.");

                return;
            }

            var userGuild = FindOrCreateGuild.Perform(user.Guild, db);
            var prefix    = PrefixHelper.ComputePrefix(context, userGuild, "someone");

            var channel = await user.GetOrCreateDMChannelAsync();

            await channel.SendMessageAsync($"{prefix} replied: {message}");
        }
        public static async Task PerformAsync(SocketCommandContext currentContext, string userName, string message, bool replyable, DataBase db)
        {
            // convert special discord tag to regular ID format
            userName = userName.StartsWith("<@!") && userName.EndsWith('>') ? userName.Substring(3, userName.Length - 4) : userName;
            userName = userName.StartsWith("<@") && userName.EndsWith('>') ? userName.Substring(2, userName.Length - 3) : userName;

            userName = userName.StartsWith('@') ? userName.Substring(1) : userName;
            try
            {
                var guildList = Send.GuildList(currentContext);
                List <SocketGuildUser> allUsersList = ToUserList(guildList);

                var userList = allUsersList.Where(x => x.Username != null &&
                                                  (
                                                      // simple username
                                                      x.Username.ToLower() == userName.ToLower() ||
                                                      // id
                                                      x.Id.ToString() == userName ||
                                                      // username with discriminator
                                                      $"{x.Username}#{x.Discriminator}".ToLower() == userName.ToLower()
                                                  ) &&
                                                  !x.IsBot);

                var allowDmList = userList.Where(x => FilterGuildByDirectMessageSetting(x, db));

                if (!allowDmList.Any() && userList.Any())
                {
                    await currentContext.Channel.SendMessageAsync("user found, but channel permissions do not allow annonymous direct messaging");

                    return;
                }

                var user = allowDmList.Where(x => FilterGuildByRole(x, currentContext.User, db)).FirstOrDefault();

                if (user == null && allowDmList.Any())
                {
                    await currentContext.Channel.SendMessageAsync("user found, but you do not have the role required to DM them");

                    return;
                }
                else if (user == null)
                {
                    await currentContext.Channel.SendMessageAsync("user not found");

                    return;
                }

                var userChannel = await user.GetOrCreateDMChannelAsync();

                var userGuild       = FindOrCreateGuild.Perform(user.Guild, db);
                var prefix          = PrefixHelper.ComputePrefix(currentContext, userGuild, "anonymous user");
                var messageFunction = Send.SendMessageToChannel(userChannel, replyable, currentContext.User);
                await messageFunction(prefix, message);

                await Send.SendSentEmote(currentContext);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Beispiel #6
0
        public static async Task PerformAsync(UnifiedContext context, string userName, string message, bool replyable, DataBase db)
        {
            // convert special discord tag to regular ID format
            userName = userName.StartsWith("<@!") && userName.EndsWith('>') ? userName.Substring(3, userName.Length - 4) : userName;
            userName = userName.StartsWith("<@") && userName.EndsWith('>') ? userName.Substring(2, userName.Length - 3) : userName;

            userName = userName.StartsWith('@') ? userName.Substring(1) : userName;
            try
            {
                var guildList = Send.GuildList(context);
                List <SocketGuildUser> allUsersList = ToUserList(guildList);

                var userList = allUsersList.Where(x => x.Username != null &&
                                                  (
                                                      // simple username
                                                      x.Username.ToLower() == userName.ToLower() ||
                                                      // id
                                                      x.Id.ToString() == userName ||
                                                      // username with discriminator
                                                      $"{x.Username}#{x.Discriminator}".ToLower() == userName.ToLower()
                                                  ) &&
                                                  !x.IsBot);

                var allowDmList = userList.Where(x => FilterGuildByDirectMessageSetting(x, db).Result);

                if (!allowDmList.Any() && userList.Any())
                {
                    await Send.SendErrorWithDeleteReaction(context, "user found, but channel permissions do not allow annonymous direct messaging");

                    return;
                }

                var requiredRoleList = allowDmList.Where(x => FilterGuildByRole(x, context.User, db));

                if (!requiredRoleList.Any() && allowDmList.Any())
                {
                    await Send.SendErrorWithDeleteReaction(context, "user found, but you do not have the role required to DM them");

                    return;
                }

                var list = requiredRoleList.ToList().Select(async x => Tuple.Create(x, await FindOrCreateGuild.Perform(x.Guild, db)));

                var userGuild = list.FirstOrDefault(x => !PrefixHelper.UserBlocked(context.User.Id, x.Result.Item2));

                if (userGuild == null && requiredRoleList.Any())
                {
                    await Send.SendErrorWithDeleteReaction(context, "user found, but you have been banned from using Voltaire on your shared server");
                }
                else if (userGuild == null)
                {
                    await Send.SendErrorWithDeleteReaction(context, "user not found");

                    return;
                }

                var userChannel = await userGuild.Result.Item1.CreateDMChannelAsync();

                var prefix          = PrefixHelper.ComputePrefix(context, userGuild.Result.Item2, "anonymous user");
                var messageFunction = Send.SendMessageToChannel(userChannel, replyable, context);
                var sentMessage     = await messageFunction(prefix, message);

                await Send.AddReactionToMessage(sentMessage);

                await Send.SendSentEmoteIfCommand(context);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            return;
        }