Blacklisting done
This commit is contained in:
		| @@ -24,6 +24,8 @@ namespace NadekoBot.Migrations | ||||
|  | ||||
|                     b.Property<ulong>("ItemId"); | ||||
|  | ||||
|                     b.Property<int>("Type"); | ||||
|  | ||||
|                     b.HasKey("Id"); | ||||
|  | ||||
|                     b.HasIndex("BotConfigId"); | ||||
|   | ||||
| @@ -197,13 +197,12 @@ namespace NadekoBot.Modules.Gambling | ||||
|             await channel.SendMessageAsync( | ||||
|                 richest.Aggregate(new StringBuilder( | ||||
| $@"```xl | ||||
|         ┏━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━┓ | ||||
|         ┃        Id           ┃  $$$  ┃ | ||||
|         "), | ||||
|                 (cur, cs) => cur.AppendLine( | ||||
| $@"┣━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━┫ | ||||
|         ┃{(channel.Guild.GetUser(cs.UserId)?.Username.TrimTo(18, true) ?? cs.UserId.ToString()),-20} ┃ {cs,5} ┃") | ||||
|                         ).ToString() + "┗━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━┛```").ConfigureAwait(false); | ||||
| ┏━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓ | ||||
| ┃        Id           ┃  $$$   ┃ | ||||
| "), | ||||
|                 (cur, cs) => cur.AppendLine($@"┣━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━━┫ | ||||
| ┃{(channel.Guild.GetUser(cs.UserId)?.Username.TrimTo(18, true) ?? cs.UserId.ToString()),-20} ┃ {cs.Amount,6} ┃") | ||||
|                         ).ToString() + "┗━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━━┛```").ConfigureAwait(false); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -13,8 +13,8 @@ namespace NadekoBot.Modules.Games.Trivia | ||||
|     { | ||||
|         private readonly SemaphoreSlim _guessLock = new SemaphoreSlim(1, 1); | ||||
|  | ||||
|         private IGuild guild { get; } | ||||
|         private ITextChannel channel { get; } | ||||
|         public IGuild guild { get; } | ||||
|         public ITextChannel channel { get; } | ||||
|  | ||||
|         private int QuestionDurationMiliseconds { get; } = 30000; | ||||
|         private int HintTimeoutMiliseconds { get; } = 6000; | ||||
|   | ||||
| @@ -43,7 +43,7 @@ namespace NadekoBot.Modules.Permissions | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     permIndex = i + 1; | ||||
|                     permIndex = i; | ||||
|                     return result.Value; | ||||
|                 } | ||||
|             } | ||||
|   | ||||
| @@ -15,7 +15,7 @@ using Discord.API; | ||||
| namespace NadekoBot.Modules.Permissions | ||||
| { | ||||
|     [NadekoModule("Permissions", ";")] | ||||
|     public class Permissions : DiscordModule | ||||
|     public partial class Permissions : DiscordModule | ||||
|     { | ||||
|         public Permissions(ILocalization loc, CommandService cmds, ShardedDiscordClient client) : base(loc, cmds, client) | ||||
|         { | ||||
|   | ||||
| @@ -98,7 +98,7 @@ namespace NadekoBot.Modules.Utility | ||||
|         public async Task UserId(IUserMessage msg, IGuildUser target = null) | ||||
|         { | ||||
|             var usr = target ?? msg.Author; | ||||
|             await msg.Reply($"Id of the user { usr.Username } is { usr.Id })").ConfigureAwait(false); | ||||
|             await msg.Reply($"Id of the user { usr.Username } is { usr.Id }").ConfigureAwait(false); | ||||
|         } | ||||
|  | ||||
|         [LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias] | ||||
|   | ||||
							
								
								
									
										122
									
								
								src/NadekoBot/Resources/CommandStrings.Designer.cs
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										122
									
								
								src/NadekoBot/Resources/CommandStrings.Designer.cs
									
									
									
										generated
									
									
									
								
							| @@ -1061,27 +1061,27 @@ namespace NadekoBot.Resources { | ||||
|         /// <summary> | ||||
|         ///    Looks up a localized string similar to Blacklists a mentioned channel (#general for example).. | ||||
|         /// </summary> | ||||
|         public static string cbl_desc { | ||||
|         public static string channelblacklist_desc { | ||||
|             get { | ||||
|                 return ResourceManager.GetString("cbl_desc", resourceCulture); | ||||
|                 return ResourceManager.GetString("channelblacklist_desc", resourceCulture); | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         /// <summary> | ||||
|         ///    Looks up a localized string similar to `;cbl #some_channel`. | ||||
|         /// </summary> | ||||
|         public static string cbl_summary { | ||||
|         public static string channelblacklist_summary { | ||||
|             get { | ||||
|                 return ResourceManager.GetString("cbl_summary", resourceCulture); | ||||
|                 return ResourceManager.GetString("channelblacklist_summary", resourceCulture); | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         /// <summary> | ||||
|         ///    Looks up a localized string similar to cbl. | ||||
|         /// </summary> | ||||
|         public static string cbl_text { | ||||
|         public static string channelblacklist_text { | ||||
|             get { | ||||
|                 return ResourceManager.GetString("cbl_text", resourceCulture); | ||||
|                 return ResourceManager.GetString("channelblacklist_text", resourceCulture); | ||||
|             } | ||||
|         } | ||||
|          | ||||
| @@ -1104,7 +1104,7 @@ namespace NadekoBot.Resources { | ||||
|         } | ||||
|          | ||||
|         /// <summary> | ||||
|         ///    Looks up a localized string similar to channelid. | ||||
|         ///    Looks up a localized string similar to channelid cid. | ||||
|         /// </summary> | ||||
|         public static string channelid_text { | ||||
|             get { | ||||
| @@ -5972,33 +5972,6 @@ namespace NadekoBot.Resources { | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         /// <summary> | ||||
|         ///    Looks up a localized string similar to Blacklists a server by a name or id (#general for example). **BOT OWNER ONLY**. | ||||
|         /// </summary> | ||||
|         public static string sbl_desc { | ||||
|             get { | ||||
|                 return ResourceManager.GetString("sbl_desc", resourceCulture); | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         /// <summary> | ||||
|         ///    Looks up a localized string similar to `;sbl [servername/serverid]`. | ||||
|         /// </summary> | ||||
|         public static string sbl_summary { | ||||
|             get { | ||||
|                 return ResourceManager.GetString("sbl_summary", resourceCulture); | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         /// <summary> | ||||
|         ///    Looks up a localized string similar to sbl. | ||||
|         /// </summary> | ||||
|         public static string sbl_text { | ||||
|             get { | ||||
|                 return ResourceManager.GetString("sbl_text", resourceCulture); | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         /// <summary> | ||||
|         ///    Looks up a localized string similar to Starts an instance of cross server channel. You will get a token as a DM that other people will use to tune in to the same instance. **Bot Owner Only.**. | ||||
|         /// </summary> | ||||
| @@ -6053,6 +6026,33 @@ namespace NadekoBot.Resources { | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         /// <summary> | ||||
|         ///    Looks up a localized string similar to Blacklists a server by a name or id (#general for example). **BOT OWNER ONLY**. | ||||
|         /// </summary> | ||||
|         public static string serverblacklist_desc { | ||||
|             get { | ||||
|                 return ResourceManager.GetString("serverblacklist_desc", resourceCulture); | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         /// <summary> | ||||
|         ///    Looks up a localized string similar to `;sbl [servername/serverid]`. | ||||
|         /// </summary> | ||||
|         public static string serverblacklist_summary { | ||||
|             get { | ||||
|                 return ResourceManager.GetString("serverblacklist_summary", resourceCulture); | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         /// <summary> | ||||
|         ///    Looks up a localized string similar to sbl. | ||||
|         /// </summary> | ||||
|         public static string serverblacklist_text { | ||||
|             get { | ||||
|                 return ResourceManager.GetString("serverblacklist_text", resourceCulture); | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         /// <summary> | ||||
|         ///    Looks up a localized string similar to Shows current server ID.. | ||||
|         /// </summary> | ||||
| @@ -7052,33 +7052,6 @@ namespace NadekoBot.Resources { | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         /// <summary> | ||||
|         ///    Looks up a localized string similar to Blacklists a mentioned user. **Bot Owner Only!**. | ||||
|         /// </summary> | ||||
|         public static string ubl_desc { | ||||
|             get { | ||||
|                 return ResourceManager.GetString("ubl_desc", resourceCulture); | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         /// <summary> | ||||
|         ///    Looks up a localized string similar to `;ubl [user_mention]`. | ||||
|         /// </summary> | ||||
|         public static string ubl_summary { | ||||
|             get { | ||||
|                 return ResourceManager.GetString("ubl_summary", resourceCulture); | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         /// <summary> | ||||
|         ///    Looks up a localized string similar to ubl. | ||||
|         /// </summary> | ||||
|         public static string ubl_text { | ||||
|             get { | ||||
|                 return ResourceManager.GetString("ubl_text", resourceCulture); | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         /// <summary> | ||||
|         ///    Looks up a localized string similar to Unbinds a bot from the channel and board. **Bot Owner Only!**. | ||||
|         /// </summary> | ||||
| @@ -7241,6 +7214,33 @@ namespace NadekoBot.Resources { | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         /// <summary> | ||||
|         ///    Looks up a localized string similar to Blacklists a mentioned user. **Bot Owner Only!**. | ||||
|         /// </summary> | ||||
|         public static string userblacklist_desc { | ||||
|             get { | ||||
|                 return ResourceManager.GetString("userblacklist_desc", resourceCulture); | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         /// <summary> | ||||
|         ///    Looks up a localized string similar to `;ubl [user_mention]`. | ||||
|         /// </summary> | ||||
|         public static string userblacklist_summary { | ||||
|             get { | ||||
|                 return ResourceManager.GetString("userblacklist_summary", resourceCulture); | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         /// <summary> | ||||
|         ///    Looks up a localized string similar to ubl. | ||||
|         /// </summary> | ||||
|         public static string userblacklist_text { | ||||
|             get { | ||||
|                 return ResourceManager.GetString("userblacklist_text", resourceCulture); | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         /// <summary> | ||||
|         ///    Looks up a localized string similar to Shows user ID.. | ||||
|         /// </summary> | ||||
|   | ||||
| @@ -919,7 +919,7 @@ | ||||
|     <value>`.uid` or `.uid "@SomeGuy"`</value> | ||||
|   </data> | ||||
|   <data name="channelid_text" xml:space="preserve"> | ||||
|     <value>channelid</value> | ||||
|     <value>channelid cid</value> | ||||
|   </data> | ||||
|   <data name="channelid_desc" xml:space="preserve"> | ||||
|     <value>Shows current channel ID.</value> | ||||
| @@ -1224,13 +1224,13 @@ | ||||
|   <data name="allrolecmds_summary" xml:space="preserve"> | ||||
|     <value>`;arc "module name" [enable/disable] MyRole`</value> | ||||
|   </data> | ||||
|   <data name="ubl_text" xml:space="preserve"> | ||||
|   <data name="userblacklist_text" xml:space="preserve"> | ||||
|     <value>ubl</value> | ||||
|   </data> | ||||
|   <data name="ubl_desc" xml:space="preserve"> | ||||
|   <data name="userblacklist_desc" xml:space="preserve"> | ||||
|     <value>Blacklists a mentioned user. **Bot Owner Only!**</value> | ||||
|   </data> | ||||
|   <data name="ubl_summary" xml:space="preserve"> | ||||
|   <data name="userblacklist_summary" xml:space="preserve"> | ||||
|     <value>`;ubl [user_mention]`</value> | ||||
|   </data> | ||||
|   <data name="uubl_text" xml:space="preserve"> | ||||
| @@ -1242,13 +1242,13 @@ | ||||
|   <data name="uubl_summary" xml:space="preserve"> | ||||
|     <value>`;uubl [user_mention]`</value> | ||||
|   </data> | ||||
|   <data name="cbl_text" xml:space="preserve"> | ||||
|   <data name="channelblacklist_text" xml:space="preserve"> | ||||
|     <value>cbl</value> | ||||
|   </data> | ||||
|   <data name="cbl_desc" xml:space="preserve"> | ||||
|   <data name="channelblacklist_desc" xml:space="preserve"> | ||||
|     <value>Blacklists a mentioned channel (#general for example).</value> | ||||
|   </data> | ||||
|   <data name="cbl_summary" xml:space="preserve"> | ||||
|   <data name="channelblacklist_summary" xml:space="preserve"> | ||||
|     <value>`;cbl #some_channel`</value> | ||||
|   </data> | ||||
|   <data name="cubl_text" xml:space="preserve"> | ||||
| @@ -1260,13 +1260,13 @@ | ||||
|   <data name="cubl_summary" xml:space="preserve"> | ||||
|     <value>`;cubl #some_channel`</value> | ||||
|   </data> | ||||
|   <data name="sbl_text" xml:space="preserve"> | ||||
|   <data name="serverblacklist_text" xml:space="preserve"> | ||||
|     <value>sbl</value> | ||||
|   </data> | ||||
|   <data name="sbl_desc" xml:space="preserve"> | ||||
|   <data name="serverblacklist_desc" xml:space="preserve"> | ||||
|     <value>Blacklists a server by a name or id (#general for example). **BOT OWNER ONLY**</value> | ||||
|   </data> | ||||
|   <data name="sbl_summary" xml:space="preserve"> | ||||
|   <data name="serverblacklist_summary" xml:space="preserve"> | ||||
|     <value>`;sbl [servername/serverid]`</value> | ||||
|   </data> | ||||
|   <data name="cmdcooldown_text" xml:space="preserve"> | ||||
|   | ||||
| @@ -39,11 +39,24 @@ namespace NadekoBot.Services | ||||
|             if (usrMsg == null) | ||||
|                 return Task.CompletedTask; | ||||
|  | ||||
|             if (usrMsg.Author.IsBot) //no bots | ||||
|                 return Task.CompletedTask; | ||||
|  | ||||
|             var guild = (msg.Channel as ITextChannel)?.Guild; | ||||
|  | ||||
|             BlacklistItem blacklistedItem; | ||||
|             if ((blacklistedItem = Permissions.BlacklistCommands.BlacklistedItems.FirstOrDefault(bi => | ||||
|                  (bi.Type == BlacklistItem.BlacklistType.Server && bi.ItemId == guild?.Id) || | ||||
|                  (bi.Type == BlacklistItem.BlacklistType.Channel && bi.ItemId == msg.Channel.Id) || | ||||
|                  (bi.Type == BlacklistItem.BlacklistType.User && bi.ItemId == usrMsg.Author.Id))) != null) | ||||
|             { | ||||
|                 _log.Warn("Attempt was made to run a command by a blacklisted {0}, id: {1}", blacklistedItem.Type, blacklistedItem.ItemId); | ||||
|                 return Task.CompletedTask; | ||||
|             } | ||||
|  | ||||
|             var throwaway = Task.Run(async () => | ||||
|             { | ||||
|               var sw = new Stopwatch(); | ||||
|                 var sw = new Stopwatch(); | ||||
|                 sw.Start(); | ||||
|  | ||||
|                 try | ||||
| @@ -165,7 +178,7 @@ namespace NadekoBot.Services | ||||
|                     int index; | ||||
|                     if (!rootPerm.AsEnumerable().CheckPermissions(message, cmd.Name, cmd.Module.Name, out index)) | ||||
|                     { | ||||
|                         var returnMsg = $"Permission number #{index} **{rootPerm.GetAt(index).GetCommand()}** is preventing this action."; | ||||
|                         var returnMsg = $"Permission number #{index + 1} **{rootPerm.GetAt(index).GetCommand()}** is preventing this action."; | ||||
|                         return new Tuple<Command, IResult>(cmd, SearchResult.FromError(CommandError.Exception, returnMsg)); | ||||
|                     } | ||||
|  | ||||
|   | ||||
| @@ -43,6 +43,8 @@ namespace NadekoBot.Services.Database.Models | ||||
|     public class BlacklistItem : DbEntity | ||||
|     { | ||||
|         public ulong ItemId { get; set; } | ||||
|         public BlacklistType Type { get; set; } | ||||
|  | ||||
|         public enum BlacklistType | ||||
|         { | ||||
|             Server, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user