Exemple #1
0
        public static async Task PerformAsync(UnifiedContext context, string identifier, DataBase db)
        {
            if (!BanIdentifier.ValidIdentifier(identifier))
            {
                await Send.SendErrorWithDeleteReaction(context, "Please use the 4 digit number following the identifier to unban users.");

                return;
            }

            var guild = await FindOrCreateGuild.Perform(context.Guild, db);

            var identifiers = guild.BannedIdentifiers.Where(x => x.Identifier == identifier);

            if (identifiers.Count() == 0)
            {
                await Send.SendErrorWithDeleteReaction(context, "That user is not currently banned.");

                return;
            }

            db.BannedIdentifiers.RemoveRange(identifiers.ToList());

            await db.SaveChangesAsync();

            await Send.SendMessageToContext(context, $"{identifier} is now unbanned");
        }
        public static async Task PerformAsync(ShardedCommandContext context, DataBase db)
        {
            try
            {
                var guild = FindOrCreateGuild.Perform(context.Guild, db);

                // toList to force enumeration before we shuffle identifier
                var bannedUsers = context.Guild.Users.Where(x => PrefixHelper.UserBlocked(x.Id, guild)).ToList();

                guild.UserIdentifierSeed = new Random().Next(int.MinValue, int.MaxValue);

                var items = bannedUsers.Select(x => PrefixHelper.GetIdentifierString(x.Id, guild)).Select(x => new BannedIdentifier {
                    Identifier = x
                });

                db.RemoveRange(guild.BannedIdentifiers);

                items.Select((x) => {
                    guild.BannedIdentifiers.Add(x);
                    return(true);
                }).ToList();

                db.SaveChanges();

                await context.Channel.SendMessageAsync(text : "User identifiers have been randomized.");
            }
            catch (Exception ex)
            {
                Console.WriteLine("error rotating");
                Console.WriteLine(ex.ToString());
            }
        }
Exemple #3
0
        public static async Task PerformAsync(UnifiedContext context, string identifier, DataBase db)
        {
            if (!ValidIdentifier(identifier))
            {
                await Send.SendErrorWithDeleteReaction(context, "Please use the 4 digit number following the identifier to ban users.");

                return;
            }

            var guild = await FindOrCreateGuild.Perform(context.Guild, db);

            if (!EnsureActiveSubscription.Perform(guild, db))
            {
                await Send.SendErrorWithDeleteReaction(context, "You need an active Voltaire Pro subscription to ban users. To get started, use `/pro`");

                return;
            }

            if (guild.BannedIdentifiers.Any(x => x.Identifier == identifier))
            {
                await Send.SendErrorWithDeleteReaction(context, "That identifier is already banned!");

                return;
            }

            guild.BannedIdentifiers.Add(new BannedIdentifier {
                Identifier = identifier
            });
            await db.SaveChangesAsync();

            await Send.SendMessageToContext(context, $"{identifier} is now banned");
        }
Exemple #4
0
        public static async Task PerformAsync(SocketCommandContext context, string identifier, DataBase db)
        {
            if (!ValidIdentifier(identifier))
            {
                await context.Channel.SendMessageAsync("Please use the 4 digit number following the identifier to ban users.");

                return;
            }

            var guild = FindOrCreateGuild.Perform(context.Guild, db);

            if (!EnsureActiveSubscription.Perform(guild, db))
            {
                await context.Channel.SendMessageAsync("You need an active Voltaire Pro subscription to ban users. To get started, use `!volt pro`");

                return;
            }

            if (guild.BannedIdentifiers.Any(x => x.Identifier == identifier))
            {
                await context.Channel.SendMessageAsync("That identifier is already banned!");

                return;
            }

            guild.BannedIdentifiers.Add(new BannedIdentifier {
                Identifier = identifier
            });
            db.SaveChanges();
            await context.Channel.SendMessageAsync(text : $"{identifier} is now banned");
        }
Exemple #5
0
        public static async Task PerformAsync(ShardedCommandContext context, DataBase db)
        {
            var guild = FindOrCreateGuild.Perform(context.Guild, db);

            if (EnsureActiveSubscription.Perform(guild, db))
            {
                var service      = new SubscriptionService();
                var subscription = service.Get(guild.SubscriptionId);
                var amount       = subscription.Plan.Amount;
                var date         = subscription.CurrentPeriodEnd;

                var message = $"Your current subscription will renew {date.Value.ToLongDateString()}.\n" +
                              $"To cancel your subscription, use the `!volt cancel` command.";

                await context.Channel.SendMessageAsync(text : message);
            }
            else
            {
                var size = context.Guild.MemberCount <= 200 ? "s" : "l";
                var url  = $"https://nminchow.github.io/VoltaireWeb/upgrade?serverId={context.Guild.Id.ToString()}&type={size}";
                var view = Views.Info.Pro.Response(url, guild, db);
                try {
                    await context.Channel.SendMessageAsync(view.Item1, embed : view.Item2);
                } catch (Discord.Net.HttpException e) {
                    await context.Channel.SendMessageAsync(text : $"Use this URL to upgrade to Volatire Pro: {url}");
                }
            }
        }
Exemple #6
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);
        }
Exemple #7
0
        public static async Task PerformAsync(ShardedCommandContext context, string identifier, DataBase db)
        {
            if (!BanIdentifier.ValidIdentifier(identifier))
            {
                await context.Channel.SendMessageAsync("Please use the 4 digit number following the identifier to unban users.");

                return;
            }

            var guild = FindOrCreateGuild.Perform(context.Guild, db);

            var identifiers = guild.BannedIdentifiers.Where(x => x.Identifier == identifier);

            if (identifiers.Count() == 0)
            {
                await context.Channel.SendMessageAsync("That user is not currently banned.");

                return;
            }

            db.BannedIdentifiers.RemoveRange(identifiers.ToList());

            db.SaveChanges();
            await context.Channel.SendMessageAsync(text : $"{identifier} is now unbanned");
        }
      public async override Task <PreconditionResult> CheckRequirementsAsync(IInteractionContext context, Discord.Interactions.ICommandInfo commandInfo, IServiceProvider services)
      {
          if (context.Guild == null)
          {
              return(PreconditionResult.FromError("This command can only be executed from within server channels."));
          }

          // possible to pass the context in?
          var db    = services.GetService <DataBase>();
          var guild = await FindOrCreateGuild.Perform(context.Guild, db);

          if (guild.AdminRole != null)
          {
              var role = context.Guild.Roles.FirstOrDefault(x => x.Id.ToString() == guild.AdminRole);
              if (role != null)
              {
                  var p = (SocketRole)role;
                  if (p.Members.Any(x => x.Id == context.User.Id))
                  {
                      return(PreconditionResult.FromSuccess());
                  }
              }
          }
          Console.WriteLine("returning default");
          return(await new RequireUserPermissionAttribute(GuildPermission.Administrator).CheckRequirementsAsync(context, commandInfo, services));
      }
Exemple #9
0
        public static async Task PerformAsync(SocketCommandContext context, DataBase db)
        {
            var guild = FindOrCreateGuild.Perform(context.Guild, db);

            guild.AllowedRole = null;
            db.SaveChanges();
            await context.Channel.SendMessageAsync(text : $"All users can now use Voltaire.");
        }
Exemple #10
0
        public static async Task PerformAsync(ShardedCommandContext context, DataBase db)
        {
            var guild = FindOrCreateGuild.Perform(context.Guild, db);

            db.RemoveRange(guild.BannedIdentifiers);
            db.SaveChanges();
            await context.Channel.SendMessageAsync(text : "Bans cleared");
        }
Exemple #11
0
        public static async Task PerformAsync(SocketCommandContext context, Boolean setting, DataBase db)
        {
            var guild = FindOrCreateGuild.Perform(context.Guild, db);

            guild.AllowDirectMessage = setting;
            db.SaveChanges();
            await context.Channel.SendMessageAsync(text : $"'Allow DM' set to {setting}");
        }
Exemple #12
0
        public static async Task PerformAsync(ShardedCommandContext context, Boolean setting, DataBase db)
        {
            var guild = FindOrCreateGuild.Perform(context.Guild, db);

            guild.UseEmbed = setting;
            db.SaveChanges();
            await context.Channel.SendMessageAsync(text : $"'Embeds' set to {setting}");
        }
Exemple #13
0
        public static async Task PerformAsync(ShardedCommandContext context, SocketRole role, DataBase db)
        {
            var guild = FindOrCreateGuild.Perform(context.Guild, db);

            guild.AllowedRole = role.Id.ToString();
            db.SaveChanges();
            await context.Channel.SendMessageAsync(text : $"{role.Name} is now the only role that can use Voltaire on this server");
        }
Exemple #14
0
        public static async Task PerformAsync(SocketCommandContext context, DataBase db)
        {
            var guild = FindOrCreateGuild.Perform(context.Guild, db);

            guild.UserIdentifierSeed = new Random().Next(int.MinValue, int.MaxValue);
            db.SaveChanges();
            await context.Channel.SendMessageAsync(text : "User identifiers have been randomized.");
        }
Exemple #15
0
        public static async Task PerformAsync(UnifiedContext context, DataBase db)
        {
            var guild = await FindOrCreateGuild.Perform(context.Guild, db);

            guild.AllowedRole = null;
            await db.SaveChangesAsync();

            await Send.SendMessageToContext(context, $"All users can now use Voltaire.");
        }
Exemple #16
0
        public static async Task PerformAsync(UnifiedContext context, SocketRole role, DataBase db)
        {
            var guild = await FindOrCreateGuild.Perform(context.Guild, db);

            guild.AllowedRole = role.Id.ToString();
            await db.SaveChangesAsync();

            await Send.SendMessageToContext(context, $"{role.Name} is now the only role that can use Voltaire on this server");
        }
        public static async Task PerformAsync(UnifiedContext context, Boolean setting, DataBase db)
        {
            var guild = await FindOrCreateGuild.Perform(context.Guild, db);

            guild.UseUserIdentifiers = setting;
            await db.SaveChangesAsync();

            await Send.SendMessageToContext(context, $"'User Identifiers' set to {setting}");
        }
Exemple #18
0
        public static async Task PerformAsync(UnifiedContext context, DataBase db)
        {
            var guild = await FindOrCreateGuild.Perform(context.Guild, db);

            db.RemoveRange(guild.BannedIdentifiers);
            await db.SaveChangesAsync();

            await Send.SendMessageToContext(context, "Bans cleared");
        }
Exemple #19
0
        public static async Task PerformAsync(SocketCommandContext context, SocketRole role, DataBase db)
        {
            var guild = FindOrCreateGuild.Perform(context.Guild, db);

            if (!EnsureActiveSubscription.Perform(guild, db))
            {
                await context.Channel.SendMessageAsync("You need an active Voltaire Pro subscription to set an admin role. To get started, use `!volt pro`");

                return;
            }

            guild.AdminRole = role.Id.ToString();
            db.SaveChanges();
            await context.Channel.SendMessageAsync(text : $"{role.Name} can now configure Voltaire and ban users on this server.");
        }
Exemple #20
0
        public static async Task PerformAsync(SocketCommandContext context, DataBase db)
        {
            var guild = FindOrCreateGuild.Perform(context.Guild, db);

            var bannedIdentifiers = guild.BannedIdentifiers.Select(x => x.Identifier).ToArray();

            if (bannedIdentifiers.Count() == 0)
            {
                await context.Channel.SendMessageAsync(text : $"No users are currently banned.");

                return;
            }

            await context.Channel.SendMessageAsync(text : $"**Banned Users:**\n{String.Join("\n", bannedIdentifiers)}");
        }
Exemple #21
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;
        }
Exemple #22
0
        public static async Task PerformAsync(ShardedCommandContext context, DataBase db)
        {
            var guild = FindOrCreateGuild.Perform(context.Guild, db);

            if (EnsureActiveSubscription.Perform(guild, db))
            {
                var service = new SubscriptionService();
                var options = new SubscriptionCancelOptions {
                    Prorate = false
                };
                service.Cancel(guild.SubscriptionId, options);

                await context.Channel.SendMessageAsync(text : "Your subscription has been canceled. Use `!volt pro` to re-upgrade at any time!");
            }
            else
            {
                await context.Channel.SendMessageAsync(text : "You do not currently have an active Voltaire Pro subscription. To create one, use the" +
                                                       " `!volt pro` command.");
            }
        }
Exemple #23
0
        public async override Task <PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services)
        {
            // possible to pass the context in?
            var db    = services.GetService <DataBase>();
            var guild = FindOrCreateGuild.Perform(context.Guild, db);

            if (guild.AdminRole != null)
            {
                var role = context.Guild.Roles.FirstOrDefault(x => x.Id.ToString() == guild.AdminRole);
                if (role != null)
                {
                    var p = (SocketRole)role;
                    if (p.Members.Any(x => x.Id == context.User.Id))
                    {
                        return(PreconditionResult.FromSuccess());
                    }
                }
            }

            return(await new RequireUserPermissionAttribute(GuildPermission.Administrator).CheckPermissionsAsync(context, command, services));
        }
Exemple #24
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);
        }
Exemple #25
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}");
        }
Exemple #26
0
        public static async Task PerformAsync(ShardedCommandContext context, DataBase db)
        {
            var guild = FindOrCreateGuild.Perform(context.Guild, db);

            if (EnsureActiveSubscription.Perform(guild, db))
            {
                var service      = new SubscriptionService();
                var subscription = service.Get(guild.SubscriptionId);
                var amount       = subscription.Plan.Amount;
                var date         = subscription.CurrentPeriodEnd;

                var message = $"Your current subscription will renew {date.Value.ToLongDateString()}.\n" +
                              $"To cancel your subscription, use the `!volt cancel` command.";

                await context.Channel.SendMessageAsync(text : message);
            }
            else
            {
                var size = context.Guild.MemberCount <= 200 ? "s" : "l";
                //var url = $"https://nminchow.github.io/VoltaireWeb/upgrade?serverId={context.Guild.Id.ToString()}&type={size}";
                var url = $"CURRENTLY NOT SUPPORTED (but everybody is pro anyway <3 )";
                await context.Channel.SendMessageAsync(text : $"Use this URL to upgrade to Volatire Pro: {url}");
            }
        }
        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());
            }
        }
        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;
        }