A lot of namespace changes
This commit is contained in:
parent
ba0cc29bd3
commit
a0f14c9cd9
@ -1,7 +1,7 @@
|
|||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using NadekoBot.Modules;
|
using NadekoBot.Modules;
|
||||||
|
|
||||||
namespace NadekoBot.Commands
|
namespace NadekoBot.Classes
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Base DiscordCommand Class.
|
/// Base DiscordCommand Class.
|
||||||
|
@ -3,9 +3,9 @@ using Discord.Commands;
|
|||||||
using Discord.Modules;
|
using Discord.Modules;
|
||||||
using NadekoBot.Classes;
|
using NadekoBot.Classes;
|
||||||
using NadekoBot.Classes._DataModels;
|
using NadekoBot.Classes._DataModels;
|
||||||
using NadekoBot.Classes.Permissions;
|
|
||||||
using NadekoBot.Extensions;
|
using NadekoBot.Extensions;
|
||||||
using NadekoBot.Modules.Administration.Commands;
|
using NadekoBot.Modules.Administration.Commands;
|
||||||
|
using NadekoBot.Modules.Permissions.Classes;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using NadekoBot.Classes.Permissions;
|
using NadekoBot.Classes;
|
||||||
using NadekoBot.Commands;
|
using NadekoBot.Modules.Permissions.Classes;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using NadekoBot.Commands;
|
using NadekoBot.Classes;
|
||||||
using NadekoBot.Extensions;
|
using NadekoBot.Extensions;
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using NadekoBot.Classes;
|
using NadekoBot.Classes;
|
||||||
using NadekoBot.Classes.Permissions;
|
using NadekoBot.Classes;
|
||||||
using NadekoBot.Commands;
|
using NadekoBot.Modules.Permissions.Classes;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using NadekoBot.Classes.Permissions;
|
using NadekoBot.Classes;
|
||||||
using NadekoBot.Commands;
|
using NadekoBot.Modules.Permissions.Classes;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Timers;
|
using System.Timers;
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using NadekoBot.Classes.JSONModels;
|
using NadekoBot.Classes.JSONModels;
|
||||||
using NadekoBot.Commands;
|
using NadekoBot.Classes;
|
||||||
using NadekoBot.Modules.Games.Commands;
|
|
||||||
using NadekoBot.Modules.Music;
|
using NadekoBot.Modules.Music;
|
||||||
|
using NadekoBot.Modules.Permissions.Classes;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -33,7 +33,7 @@ namespace NadekoBot.Modules.Administration.Commands
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{"%queued%", () => MusicModule.MusicPlayers.Sum(kvp => kvp.Value.Playlist.Count).ToString()},
|
{"%queued%", () => MusicModule.MusicPlayers.Sum(kvp => kvp.Value.Playlist.Count).ToString()},
|
||||||
{"%trivia%", () => Trivia.RunningTrivias.Count.ToString()}
|
{"%trivia%", () => Games.Commands.TriviaCommands.RunningTrivias.Count.ToString()}
|
||||||
};
|
};
|
||||||
|
|
||||||
private readonly object playingPlaceholderLock = new object();
|
private readonly object playingPlaceholderLock = new object();
|
||||||
@ -89,7 +89,7 @@ namespace NadekoBot.Modules.Administration.Commands
|
|||||||
cgb.CreateCommand(Module.Prefix + "rotateplaying")
|
cgb.CreateCommand(Module.Prefix + "rotateplaying")
|
||||||
.Alias(Module.Prefix + "ropl")
|
.Alias(Module.Prefix + "ropl")
|
||||||
.Description("Toggles rotation of playing status of the dynamic strings you specified earlier.")
|
.Description("Toggles rotation of playing status of the dynamic strings you specified earlier.")
|
||||||
.AddCheck(Classes.Permissions.SimpleCheckers.OwnerOnly())
|
.AddCheck(SimpleCheckers.OwnerOnly())
|
||||||
.Do(DoFunc());
|
.Do(DoFunc());
|
||||||
|
|
||||||
cgb.CreateCommand(Module.Prefix + "addplaying")
|
cgb.CreateCommand(Module.Prefix + "addplaying")
|
||||||
@ -97,7 +97,7 @@ namespace NadekoBot.Modules.Administration.Commands
|
|||||||
.Description("Adds a specified string to the list of playing strings to rotate. " +
|
.Description("Adds a specified string to the list of playing strings to rotate. " +
|
||||||
"Supported placeholders: " + string.Join(", ", PlayingPlaceholders.Keys))
|
"Supported placeholders: " + string.Join(", ", PlayingPlaceholders.Keys))
|
||||||
.Parameter("text", ParameterType.Unparsed)
|
.Parameter("text", ParameterType.Unparsed)
|
||||||
.AddCheck(Classes.Permissions.SimpleCheckers.OwnerOnly())
|
.AddCheck(SimpleCheckers.OwnerOnly())
|
||||||
.Do(async e =>
|
.Do(async e =>
|
||||||
{
|
{
|
||||||
var arg = e.GetArg("text");
|
var arg = e.GetArg("text");
|
||||||
@ -114,7 +114,7 @@ namespace NadekoBot.Modules.Administration.Commands
|
|||||||
cgb.CreateCommand(Module.Prefix + "listplaying")
|
cgb.CreateCommand(Module.Prefix + "listplaying")
|
||||||
.Alias(Module.Prefix + "lipl")
|
.Alias(Module.Prefix + "lipl")
|
||||||
.Description("Lists all playing statuses with their corresponding number.")
|
.Description("Lists all playing statuses with their corresponding number.")
|
||||||
.AddCheck(Classes.Permissions.SimpleCheckers.OwnerOnly())
|
.AddCheck(SimpleCheckers.OwnerOnly())
|
||||||
.Do(async e =>
|
.Do(async e =>
|
||||||
{
|
{
|
||||||
if (NadekoBot.Config.RotatingStatuses.Count == 0)
|
if (NadekoBot.Config.RotatingStatuses.Count == 0)
|
||||||
@ -132,7 +132,7 @@ namespace NadekoBot.Modules.Administration.Commands
|
|||||||
.Alias(Module.Prefix + "repl", Module.Prefix + "rmpl")
|
.Alias(Module.Prefix + "repl", Module.Prefix + "rmpl")
|
||||||
.Description("Removes a playing string on a given number.")
|
.Description("Removes a playing string on a given number.")
|
||||||
.Parameter("number", ParameterType.Required)
|
.Parameter("number", ParameterType.Required)
|
||||||
.AddCheck(Classes.Permissions.SimpleCheckers.OwnerOnly())
|
.AddCheck(SimpleCheckers.OwnerOnly())
|
||||||
.Do(async e =>
|
.Do(async e =>
|
||||||
{
|
{
|
||||||
var arg = e.GetArg("number");
|
var arg = e.GetArg("number");
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using NadekoBot.Classes.Permissions;
|
using NadekoBot.Classes;
|
||||||
using NadekoBot.Commands;
|
using NadekoBot.Modules.Permissions.Classes;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using NadekoBot.Classes;
|
using NadekoBot.Classes;
|
||||||
using NadekoBot.Classes._DataModels;
|
using NadekoBot.Classes._DataModels;
|
||||||
using NadekoBot.Commands;
|
using NadekoBot.Classes;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using NadekoBot.Classes;
|
using NadekoBot.Classes;
|
||||||
using NadekoBot.Classes.Permissions;
|
using NadekoBot.Classes;
|
||||||
using NadekoBot.Commands;
|
using NadekoBot.Modules.Permissions.Classes;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -27,7 +27,8 @@ namespace NadekoBot.Modules.Administration.Commands
|
|||||||
var role = e.Server.FindRoles(arg.Trim()).FirstOrDefault();
|
var role = e.Server.FindRoles(arg.Trim()).FirstOrDefault();
|
||||||
if (role == null)
|
if (role == null)
|
||||||
msg.AppendLine($":anger:Role **{arg}** not found.");
|
msg.AppendLine($":anger:Role **{arg}** not found.");
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
if (config.ListOfSelfAssignableRoles.Contains(role.Id))
|
if (config.ListOfSelfAssignableRoles.Contains(role.Id))
|
||||||
{
|
{
|
||||||
msg.AppendLine($":anger:Role **{role.Name}** is already in the list.");
|
msg.AppendLine($":anger:Role **{role.Name}** is already in the list.");
|
||||||
@ -81,7 +82,8 @@ namespace NadekoBot.Modules.Administration.Commands
|
|||||||
msg.Append($"`{roleId} not found. Cleaned up.`, ");
|
msg.Append($"`{roleId} not found. Cleaned up.`, ");
|
||||||
toRemove.Add(roleId);
|
toRemove.Add(roleId);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
msg.Append($"**{role.Name}**, ");
|
msg.Append($"**{role.Name}**, ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using NadekoBot.Commands;
|
using NadekoBot.Classes;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using NadekoBot.Commands;
|
using NadekoBot.Classes;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using NadekoBot.Classes;
|
using NadekoBot.Classes;
|
||||||
using NadekoBot.Classes.Permissions;
|
using NadekoBot.Classes;
|
||||||
using NadekoBot.Commands;
|
using NadekoBot.Modules.Permissions.Classes;
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using ChPermOverride = Discord.ChannelPermissionOverrides;
|
using ChPermOverride = Discord.ChannelPermissionOverrides;
|
||||||
|
@ -4,7 +4,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace NadekoBot.Commands.Conversations.Commands
|
namespace NadekoBot.Classes.Conversations.Commands
|
||||||
{
|
{
|
||||||
internal class CopyCommand : DiscordCommand
|
internal class CopyCommand : DiscordCommand
|
||||||
{
|
{
|
||||||
|
@ -4,7 +4,7 @@ using NadekoBot.Modules;
|
|||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace NadekoBot.Commands.Conversations.Commands
|
namespace NadekoBot.Classes.Conversations.Commands
|
||||||
{
|
{
|
||||||
internal class RequestsCommand : DiscordCommand
|
internal class RequestsCommand : DiscordCommand
|
||||||
{
|
{
|
||||||
|
@ -2,8 +2,9 @@ using Discord;
|
|||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Discord.Modules;
|
using Discord.Modules;
|
||||||
using NadekoBot.Classes;
|
using NadekoBot.Classes;
|
||||||
using NadekoBot.Commands.Conversations.Commands;
|
using NadekoBot.Classes.Conversations.Commands;
|
||||||
using NadekoBot.Extensions;
|
using NadekoBot.Extensions;
|
||||||
|
using NadekoBot.Modules.Permissions.Classes;
|
||||||
using NadekoBot.Properties;
|
using NadekoBot.Properties;
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
@ -32,7 +33,7 @@ namespace NadekoBot.Modules.Conversations
|
|||||||
|
|
||||||
manager.CreateCommands("", cgb =>
|
manager.CreateCommands("", cgb =>
|
||||||
{
|
{
|
||||||
cgb.AddCheck(Classes.Permissions.PermissionChecker.Instance);
|
cgb.AddCheck(PermissionChecker.Instance);
|
||||||
|
|
||||||
cgb.CreateCommand("e")
|
cgb.CreateCommand("e")
|
||||||
.Description("You did it. Or someone else!")
|
.Description("You did it. Or someone else!")
|
||||||
@ -123,7 +124,7 @@ namespace NadekoBot.Modules.Conversations
|
|||||||
{
|
{
|
||||||
var client = manager.Client;
|
var client = manager.Client;
|
||||||
|
|
||||||
cgb.AddCheck(Classes.Permissions.PermissionChecker.Instance);
|
cgb.AddCheck(PermissionChecker.Instance);
|
||||||
|
|
||||||
commands.ForEach(cmd => cmd.Init(cgb));
|
commands.ForEach(cmd => cmd.Init(cgb));
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using Discord.Modules;
|
using Discord.Modules;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using NadekoBot.Commands;
|
using NadekoBot.Classes;
|
||||||
|
|
||||||
namespace NadekoBot.Modules {
|
namespace NadekoBot.Modules {
|
||||||
internal abstract class DiscordModule : IModule {
|
internal abstract class DiscordModule : IModule {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using NadekoBot.Commands;
|
using NadekoBot.Classes;
|
||||||
using NadekoBot.Extensions;
|
using NadekoBot.Extensions;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using NadekoBot.Commands;
|
using NadekoBot.Classes;
|
||||||
using NadekoBot.Extensions;
|
using NadekoBot.Extensions;
|
||||||
using NadekoBot.Modules.Gambling.Helpers;
|
using NadekoBot.Modules.Gambling.Helpers;
|
||||||
using System;
|
using System;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using NadekoBot.Commands;
|
using NadekoBot.Classes;
|
||||||
using NadekoBot.Extensions;
|
using NadekoBot.Extensions;
|
||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
@ -3,6 +3,7 @@ using Discord.Commands;
|
|||||||
using Discord.Modules;
|
using Discord.Modules;
|
||||||
using NadekoBot.Classes;
|
using NadekoBot.Classes;
|
||||||
using NadekoBot.Extensions;
|
using NadekoBot.Extensions;
|
||||||
|
using NadekoBot.Modules.Permissions.Classes;
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -25,7 +26,7 @@ namespace NadekoBot.Modules.Gambling
|
|||||||
{
|
{
|
||||||
manager.CreateCommands("", cgb =>
|
manager.CreateCommands("", cgb =>
|
||||||
{
|
{
|
||||||
cgb.AddCheck(Classes.Permissions.PermissionChecker.Instance);
|
cgb.AddCheck(PermissionChecker.Instance);
|
||||||
|
|
||||||
commands.ForEach(com => com.Init(cgb));
|
commands.ForEach(com => com.Init(cgb));
|
||||||
|
|
||||||
@ -72,7 +73,7 @@ namespace NadekoBot.Modules.Gambling
|
|||||||
|
|
||||||
cgb.CreateCommand(Prefix + "award")
|
cgb.CreateCommand(Prefix + "award")
|
||||||
.Description("Gives someone a certain amount of flowers. **Owner only!**")
|
.Description("Gives someone a certain amount of flowers. **Owner only!**")
|
||||||
.AddCheck(Classes.Permissions.SimpleCheckers.OwnerOnly())
|
.AddCheck(SimpleCheckers.OwnerOnly())
|
||||||
.Parameter("amount", ParameterType.Required)
|
.Parameter("amount", ParameterType.Required)
|
||||||
.Parameter("receiver", ParameterType.Unparsed)
|
.Parameter("receiver", ParameterType.Unparsed)
|
||||||
.Do(async e =>
|
.Do(async e =>
|
||||||
@ -94,7 +95,7 @@ namespace NadekoBot.Modules.Gambling
|
|||||||
|
|
||||||
cgb.CreateCommand(Prefix + "take")
|
cgb.CreateCommand(Prefix + "take")
|
||||||
.Description("Takes a certain amount of flowers from someone. **Owner only!**")
|
.Description("Takes a certain amount of flowers from someone. **Owner only!**")
|
||||||
.AddCheck(Classes.Permissions.SimpleCheckers.OwnerOnly())
|
.AddCheck(SimpleCheckers.OwnerOnly())
|
||||||
.Parameter("amount", ParameterType.Required)
|
.Parameter("amount", ParameterType.Required)
|
||||||
.Parameter("rektperson", ParameterType.Unparsed)
|
.Parameter("rektperson", ParameterType.Unparsed)
|
||||||
.Do(async e =>
|
.Do(async e =>
|
||||||
@ -144,9 +145,9 @@ namespace NadekoBot.Modules.Gambling
|
|||||||
await e.Channel.SendMessage("💢 Role not found.");
|
await e.Channel.SendMessage("💢 Role not found.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var members = role.Members.Where(u => u.Status == Discord.UserStatus.Online); // only online
|
var members = role.Members.Where(u => u.Status == UserStatus.Online); // only online
|
||||||
var membersArray = members as User[] ?? members.ToArray();
|
var membersArray = members as User[] ?? members.ToArray();
|
||||||
var usr = membersArray[new System.Random().Next(0, membersArray.Length)];
|
var usr = membersArray[new Random().Next(0, membersArray.Length)];
|
||||||
await e.Channel.SendMessage($"**Raffled user:** {usr.Name} (id: {usr.Id})");
|
await e.Channel.SendMessage($"**Raffled user:** {usr.Name} (id: {usr.Id})");
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using NadekoBot.Commands;
|
using NadekoBot.Classes;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using NadekoBot.Commands;
|
using NadekoBot.Classes;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Timers;
|
using System.Timers;
|
||||||
using static NadekoBot.Modules.Games.Commands.Bomberman;
|
using static NadekoBot.Modules.Games.Commands.Bomberman;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using NadekoBot.Classes;
|
using NadekoBot.Classes;
|
||||||
using NadekoBot.Commands;
|
using NadekoBot.Classes;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using NadekoBot.Commands;
|
using NadekoBot.Classes;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using NadekoBot.Classes;
|
using NadekoBot.Classes;
|
||||||
using NadekoBot.Classes._DataModels;
|
using NadekoBot.Classes._DataModels;
|
||||||
using NadekoBot.Commands;
|
using NadekoBot.Classes;
|
||||||
using NadekoBot.Extensions;
|
using NadekoBot.Extensions;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
|
using NadekoBot.Classes;
|
||||||
using NadekoBot.Extensions;
|
using NadekoBot.Extensions;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
@ -9,7 +10,7 @@ using System.Text;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace NadekoBot.Classes.Trivia
|
namespace NadekoBot.Modules.Games.Commands.Trivia
|
||||||
{
|
{
|
||||||
internal class TriviaGame
|
internal class TriviaGame
|
||||||
{
|
{
|
||||||
@ -96,7 +97,7 @@ namespace NadekoBot.Classes.Trivia
|
|||||||
ShouldStopGame = true;
|
ShouldStopGame = true;
|
||||||
await channel.SendMessage("**Trivia game ended**\n" + GetLeaderboard());
|
await channel.SendMessage("**Trivia game ended**\n" + GetLeaderboard());
|
||||||
TriviaGame throwAwayValue;
|
TriviaGame throwAwayValue;
|
||||||
Modules.Games.Commands.Trivia.RunningTrivias.TryRemove(server.Id, out throwAwayValue);
|
TriviaCommands.RunningTrivias.TryRemove(server.Id, out throwAwayValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task StopGame()
|
public async Task StopGame()
|
@ -4,8 +4,10 @@ using System.Collections.Generic;
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
// THANKS @ShoMinamimoto for suggestions and coding help
|
// THANKS @ShoMinamimoto for suggestions and coding help
|
||||||
namespace NadekoBot.Classes.Trivia {
|
namespace NadekoBot.Modules.Games.Commands.Trivia
|
||||||
public class TriviaQuestion {
|
{
|
||||||
|
public class TriviaQuestion
|
||||||
|
{
|
||||||
//represents the min size to judge levDistance with
|
//represents the min size to judge levDistance with
|
||||||
private static readonly HashSet<Tuple<int, int>> strictness = new HashSet<Tuple<int, int>> {
|
private static readonly HashSet<Tuple<int, int>> strictness = new HashSet<Tuple<int, int>> {
|
||||||
new Tuple<int, int>(9, 0),
|
new Tuple<int, int>(9, 0),
|
||||||
@ -19,7 +21,8 @@ namespace NadekoBot.Classes.Trivia {
|
|||||||
public string Question;
|
public string Question;
|
||||||
public string Answer;
|
public string Answer;
|
||||||
|
|
||||||
public TriviaQuestion(string q, string a, string c) {
|
public TriviaQuestion(string q, string a, string c)
|
||||||
|
{
|
||||||
this.Question = q;
|
this.Question = q;
|
||||||
this.Answer = a;
|
this.Answer = a;
|
||||||
this.Category = c;
|
this.Category = c;
|
||||||
@ -27,14 +30,17 @@ namespace NadekoBot.Classes.Trivia {
|
|||||||
|
|
||||||
public string GetHint() => Answer.Scramble();
|
public string GetHint() => Answer.Scramble();
|
||||||
|
|
||||||
public bool IsAnswerCorrect(string guess) {
|
public bool IsAnswerCorrect(string guess)
|
||||||
|
{
|
||||||
guess = CleanGuess(guess);
|
guess = CleanGuess(guess);
|
||||||
if (Answer.Equals(guess)) {
|
if (Answer.Equals(guess))
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Answer = CleanGuess(Answer);
|
Answer = CleanGuess(Answer);
|
||||||
guess = CleanGuess(guess);
|
guess = CleanGuess(guess);
|
||||||
if (Answer.Equals(guess)) {
|
if (Answer.Equals(guess))
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,9 +48,12 @@ namespace NadekoBot.Classes.Trivia {
|
|||||||
return JudgeGuess(Answer.Length, guess.Length, levDistance);
|
return JudgeGuess(Answer.Length, guess.Length, levDistance);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool JudgeGuess(int guessLength, int answerLength, int levDistance) {
|
private bool JudgeGuess(int guessLength, int answerLength, int levDistance)
|
||||||
foreach (Tuple<int, int> level in strictness) {
|
{
|
||||||
if (guessLength <= level.Item1 || answerLength <= level.Item1) {
|
foreach (Tuple<int, int> level in strictness)
|
||||||
|
{
|
||||||
|
if (guessLength <= level.Item1 || answerLength <= level.Item1)
|
||||||
|
{
|
||||||
if (levDistance <= level.Item2)
|
if (levDistance <= level.Item2)
|
||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
@ -54,7 +63,8 @@ namespace NadekoBot.Classes.Trivia {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string CleanGuess(string str) {
|
private string CleanGuess(string str)
|
||||||
|
{
|
||||||
str = " " + str.ToLower() + " ";
|
str = " " + str.ToLower() + " ";
|
||||||
str = Regex.Replace(str, "\\s+", " ");
|
str = Regex.Replace(str, "\\s+", " ");
|
||||||
str = Regex.Replace(str, "[^\\w\\d\\s]", "");
|
str = Regex.Replace(str, "[^\\w\\d\\s]", "");
|
@ -4,8 +4,10 @@ using System.Collections.Generic;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace NadekoBot.Classes.Trivia {
|
namespace NadekoBot.Modules.Games.Commands.Trivia
|
||||||
public class TriviaQuestionPool {
|
{
|
||||||
|
public class TriviaQuestionPool
|
||||||
|
{
|
||||||
public static TriviaQuestionPool Instance { get; } = new TriviaQuestionPool();
|
public static TriviaQuestionPool Instance { get; } = new TriviaQuestionPool();
|
||||||
|
|
||||||
public HashSet<TriviaQuestion> pool = new HashSet<TriviaQuestion>();
|
public HashSet<TriviaQuestion> pool = new HashSet<TriviaQuestion>();
|
||||||
@ -14,20 +16,24 @@ namespace NadekoBot.Classes.Trivia {
|
|||||||
|
|
||||||
static TriviaQuestionPool() { }
|
static TriviaQuestionPool() { }
|
||||||
|
|
||||||
private TriviaQuestionPool() {
|
private TriviaQuestionPool()
|
||||||
|
{
|
||||||
Reload();
|
Reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
public TriviaQuestion GetRandomQuestion(IEnumerable<TriviaQuestion> exclude) {
|
public TriviaQuestion GetRandomQuestion(IEnumerable<TriviaQuestion> exclude)
|
||||||
|
{
|
||||||
var list = pool.Except(exclude).ToList();
|
var list = pool.Except(exclude).ToList();
|
||||||
var rand = rng.Next(0, list.Count);
|
var rand = rng.Next(0, list.Count);
|
||||||
return list[rand];
|
return list[rand];
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void Reload() {
|
internal void Reload()
|
||||||
|
{
|
||||||
var arr = JArray.Parse(File.ReadAllText("data/questions.json"));
|
var arr = JArray.Parse(File.ReadAllText("data/questions.json"));
|
||||||
|
|
||||||
foreach (var item in arr) {
|
foreach (var item in arr)
|
||||||
|
{
|
||||||
var tq = new TriviaQuestion(item["Question"].ToString(), item["Answer"].ToString(), item["Category"]?.ToString());
|
var tq = new TriviaQuestion(item["Question"].ToString(), item["Answer"].ToString(), item["Category"]?.ToString());
|
||||||
pool.Add(tq);
|
pool.Add(tq);
|
||||||
}
|
}
|
@ -1,15 +1,19 @@
|
|||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using NadekoBot.Commands;
|
using NadekoBot.Classes;
|
||||||
|
using NadekoBot.Modules.Games.Commands.Trivia;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using TriviaGame = NadekoBot.Classes.Trivia.TriviaGame;
|
|
||||||
|
|
||||||
namespace NadekoBot.Modules.Games.Commands
|
namespace NadekoBot.Modules.Games.Commands
|
||||||
{
|
{
|
||||||
internal class Trivia : DiscordCommand
|
internal class TriviaCommands : DiscordCommand
|
||||||
{
|
{
|
||||||
public static ConcurrentDictionary<ulong, TriviaGame> RunningTrivias = new ConcurrentDictionary<ulong, TriviaGame>();
|
public static ConcurrentDictionary<ulong, TriviaGame> RunningTrivias = new ConcurrentDictionary<ulong, TriviaGame>();
|
||||||
|
|
||||||
|
public TriviaCommands(DiscordModule module) : base(module)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
internal override void Init(CommandGroupBuilder cgb)
|
internal override void Init(CommandGroupBuilder cgb)
|
||||||
{
|
{
|
||||||
cgb.CreateCommand(Module.Prefix + "t")
|
cgb.CreateCommand(Module.Prefix + "t")
|
||||||
@ -57,7 +61,5 @@ namespace NadekoBot.Modules.Games.Commands
|
|||||||
await e.Channel.SendMessage("No trivia is running on this server.");
|
await e.Channel.SendMessage("No trivia is running on this server.");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public Trivia(DiscordModule module) : base(module) { }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Discord.Modules;
|
using Discord.Modules;
|
||||||
using NadekoBot.Commands;
|
|
||||||
using NadekoBot.Extensions;
|
using NadekoBot.Extensions;
|
||||||
using NadekoBot.Modules.Games.Commands;
|
using NadekoBot.Modules.Games.Commands;
|
||||||
|
using NadekoBot.Modules.Permissions.Classes;
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
@ -14,7 +14,7 @@ namespace NadekoBot.Modules.Games
|
|||||||
|
|
||||||
public GamesModule()
|
public GamesModule()
|
||||||
{
|
{
|
||||||
commands.Add(new Trivia(this));
|
commands.Add(new TriviaCommands(this));
|
||||||
commands.Add(new SpeedTyping(this));
|
commands.Add(new SpeedTyping(this));
|
||||||
commands.Add(new PollCommand(this));
|
commands.Add(new PollCommand(this));
|
||||||
commands.Add(new PlantPick(this));
|
commands.Add(new PlantPick(this));
|
||||||
@ -30,7 +30,7 @@ namespace NadekoBot.Modules.Games
|
|||||||
manager.CreateCommands("", cgb =>
|
manager.CreateCommands("", cgb =>
|
||||||
{
|
{
|
||||||
|
|
||||||
cgb.AddCheck(Classes.Permissions.PermissionChecker.Instance);
|
cgb.AddCheck(PermissionChecker.Instance);
|
||||||
|
|
||||||
commands.ForEach(cmd => cmd.Init(cgb));
|
commands.ForEach(cmd => cmd.Init(cgb));
|
||||||
|
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using NadekoBot.Extensions;
|
using NadekoBot.Extensions;
|
||||||
using NadekoBot.Modules;
|
using NadekoBot.Modules;
|
||||||
|
using NadekoBot.Modules.Permissions.Classes;
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace NadekoBot.Commands.Help.Commands
|
namespace NadekoBot.Classes.Help.Commands
|
||||||
{
|
{
|
||||||
internal class HelpCommand : DiscordCommand
|
internal class HelpCommand : DiscordCommand
|
||||||
{
|
{
|
||||||
@ -104,7 +105,7 @@ Version: `{NadekoStats.Instance.BotVersion}`";
|
|||||||
.Do(DoFunc());
|
.Do(DoFunc());
|
||||||
cgb.CreateCommand(Module.Prefix + "hgit")
|
cgb.CreateCommand(Module.Prefix + "hgit")
|
||||||
.Description("Generates the commandlist.md file. **Owner Only!**")
|
.Description("Generates the commandlist.md file. **Owner Only!**")
|
||||||
.AddCheck(Classes.Permissions.SimpleCheckers.OwnerOnly())
|
.AddCheck(SimpleCheckers.OwnerOnly())
|
||||||
.Do(DoGitFunc());
|
.Do(DoGitFunc());
|
||||||
cgb.CreateCommand(Module.Prefix + "readme")
|
cgb.CreateCommand(Module.Prefix + "readme")
|
||||||
.Alias(Module.Prefix + "guide")
|
.Alias(Module.Prefix + "guide")
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Discord.Modules;
|
using Discord.Modules;
|
||||||
using NadekoBot.Commands.Help.Commands;
|
using NadekoBot.Classes.Help.Commands;
|
||||||
using NadekoBot.Extensions;
|
using NadekoBot.Extensions;
|
||||||
|
using NadekoBot.Modules.Permissions.Classes;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace NadekoBot.Modules.Help
|
namespace NadekoBot.Modules.Help
|
||||||
@ -20,7 +21,7 @@ namespace NadekoBot.Modules.Help
|
|||||||
{
|
{
|
||||||
manager.CreateCommands("", cgb =>
|
manager.CreateCommands("", cgb =>
|
||||||
{
|
{
|
||||||
cgb.AddCheck(Classes.Permissions.PermissionChecker.Instance);
|
cgb.AddCheck(PermissionChecker.Instance);
|
||||||
commands.ForEach(com => com.Init(cgb));
|
commands.ForEach(com => com.Init(cgb));
|
||||||
|
|
||||||
cgb.CreateCommand(Prefix + "modules")
|
cgb.CreateCommand(Prefix + "modules")
|
||||||
|
@ -4,8 +4,8 @@ using Discord.Modules;
|
|||||||
using NadekoBot.Classes;
|
using NadekoBot.Classes;
|
||||||
using NadekoBot.Classes._DataModels;
|
using NadekoBot.Classes._DataModels;
|
||||||
using NadekoBot.Classes.Music;
|
using NadekoBot.Classes.Music;
|
||||||
using NadekoBot.Classes.Permissions;
|
|
||||||
using NadekoBot.Extensions;
|
using NadekoBot.Extensions;
|
||||||
|
using NadekoBot.Modules.Permissions.Classes;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Discord.Modules;
|
using Discord.Modules;
|
||||||
using NadekoBot.Classes;
|
using NadekoBot.Classes;
|
||||||
|
using NadekoBot.Modules.Permissions.Classes;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
@ -18,7 +19,7 @@ namespace NadekoBot.Modules.NSFW
|
|||||||
manager.CreateCommands("", cgb =>
|
manager.CreateCommands("", cgb =>
|
||||||
{
|
{
|
||||||
|
|
||||||
cgb.AddCheck(Classes.Permissions.PermissionChecker.Instance);
|
cgb.AddCheck(PermissionChecker.Instance);
|
||||||
|
|
||||||
cgb.CreateCommand(Prefix + "hentai")
|
cgb.CreateCommand(Prefix + "hentai")
|
||||||
.Description("Shows a random NSFW hentai image from gelbooru and danbooru with a given tag. Tag is optional but preffered. (multiple tags are appended with +)\n**Usage**: ~hentai yuri+kissing")
|
.Description("Shows a random NSFW hentai image from gelbooru and danbooru with a given tag. Tag is optional but preffered. (multiple tags are appended with +)\n**Usage**: ~hentai yuri+kissing")
|
||||||
|
@ -6,7 +6,7 @@ using System;
|
|||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace NadekoBot.Classes.Permissions
|
namespace NadekoBot.Modules.Permissions.Classes
|
||||||
{
|
{
|
||||||
|
|
||||||
internal class PermissionChecker : IPermissionChecker
|
internal class PermissionChecker : IPermissionChecker
|
@ -1,16 +1,21 @@
|
|||||||
using System;
|
using Discord;
|
||||||
using System.Linq;
|
|
||||||
using Discord;
|
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Discord.Modules;
|
using Discord.Modules;
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace NadekoBot.Classes.Permissions {
|
namespace NadekoBot.Modules.Permissions.Classes
|
||||||
internal static class PermissionHelper {
|
{
|
||||||
public static bool ValidateBool(string passedArg) {
|
internal static class PermissionHelper
|
||||||
if (string.IsNullOrWhiteSpace(passedArg)) {
|
{
|
||||||
|
public static bool ValidateBool(string passedArg)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(passedArg))
|
||||||
|
{
|
||||||
throw new ArgumentException("No value supplied! Missing argument");
|
throw new ArgumentException("No value supplied! Missing argument");
|
||||||
}
|
}
|
||||||
switch (passedArg.ToLower()) {
|
switch (passedArg.ToLower())
|
||||||
|
{
|
||||||
case "1":
|
case "1":
|
||||||
case "t":
|
case "t":
|
||||||
case "true":
|
case "true":
|
||||||
@ -32,29 +37,34 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static string ValidateModule(string mod) {
|
internal static string ValidateModule(string mod)
|
||||||
|
{
|
||||||
if (string.IsNullOrWhiteSpace(mod))
|
if (string.IsNullOrWhiteSpace(mod))
|
||||||
throw new ArgumentNullException(nameof(mod));
|
throw new ArgumentNullException(nameof(mod));
|
||||||
|
|
||||||
foreach (var m in NadekoBot.Client.GetService<ModuleService>().Modules) {
|
foreach (var m in NadekoBot.Client.GetService<ModuleService>().Modules)
|
||||||
|
{
|
||||||
if (m.Name.ToLower().Equals(mod.Trim().ToLower()))
|
if (m.Name.ToLower().Equals(mod.Trim().ToLower()))
|
||||||
return m.Name;
|
return m.Name;
|
||||||
}
|
}
|
||||||
throw new ArgumentException("That module does not exist.");
|
throw new ArgumentException("That module does not exist.");
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static string ValidateCommand(string commandText) {
|
internal static string ValidateCommand(string commandText)
|
||||||
|
{
|
||||||
if (string.IsNullOrWhiteSpace(commandText))
|
if (string.IsNullOrWhiteSpace(commandText))
|
||||||
throw new ArgumentNullException(nameof(commandText));
|
throw new ArgumentNullException(nameof(commandText));
|
||||||
|
|
||||||
foreach (var com in NadekoBot.Client.GetService<CommandService>().AllCommands) {
|
foreach (var com in NadekoBot.Client.GetService<CommandService>().AllCommands)
|
||||||
|
{
|
||||||
if (com.Text.ToLower().Equals(commandText.Trim().ToLower()))
|
if (com.Text.ToLower().Equals(commandText.Trim().ToLower()))
|
||||||
return com.Text;
|
return com.Text;
|
||||||
}
|
}
|
||||||
throw new NullReferenceException("That command does not exist.");
|
throw new NullReferenceException("That command does not exist.");
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static Role ValidateRole(Server server, string roleName) {
|
internal static Role ValidateRole(Server server, string roleName)
|
||||||
|
{
|
||||||
if (string.IsNullOrWhiteSpace(roleName))
|
if (string.IsNullOrWhiteSpace(roleName))
|
||||||
throw new ArgumentNullException(nameof(roleName));
|
throw new ArgumentNullException(nameof(roleName));
|
||||||
|
|
||||||
@ -66,7 +76,8 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
return role;
|
return role;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static Channel ValidateChannel(Server server, string channelName) {
|
internal static Channel ValidateChannel(Server server, string channelName)
|
||||||
|
{
|
||||||
if (string.IsNullOrWhiteSpace(channelName))
|
if (string.IsNullOrWhiteSpace(channelName))
|
||||||
throw new ArgumentNullException(nameof(channelName));
|
throw new ArgumentNullException(nameof(channelName));
|
||||||
var channel = server.FindChannels(channelName.Trim(), ChannelType.Text).FirstOrDefault();
|
var channel = server.FindChannels(channelName.Trim(), ChannelType.Text).FirstOrDefault();
|
||||||
@ -75,7 +86,8 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
return channel;
|
return channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static User ValidateUser(Server server, string userName) {
|
internal static User ValidateUser(Server server, string userName)
|
||||||
|
{
|
||||||
if (string.IsNullOrWhiteSpace(userName))
|
if (string.IsNullOrWhiteSpace(userName))
|
||||||
throw new ArgumentNullException(nameof(userName));
|
throw new ArgumentNullException(nameof(userName));
|
||||||
var user = server.FindUsers(userName.Trim()).FirstOrDefault();
|
var user = server.FindUsers(userName.Trim()).FirstOrDefault();
|
@ -1,40 +1,48 @@
|
|||||||
using Discord;
|
using Discord;
|
||||||
|
using Discord.Commands;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Discord.Commands;
|
|
||||||
|
|
||||||
namespace NadekoBot.Classes.Permissions {
|
namespace NadekoBot.Modules.Permissions.Classes
|
||||||
public static class PermissionsHandler {
|
{
|
||||||
|
public static class PermissionsHandler
|
||||||
|
{
|
||||||
public static ConcurrentDictionary<ulong, ServerPermissions> PermissionsDict =
|
public static ConcurrentDictionary<ulong, ServerPermissions> PermissionsDict =
|
||||||
new ConcurrentDictionary<ulong, ServerPermissions>();
|
new ConcurrentDictionary<ulong, ServerPermissions>();
|
||||||
|
|
||||||
public enum PermissionBanType {
|
public enum PermissionBanType
|
||||||
|
{
|
||||||
None, ServerBanCommand, ServerBanModule,
|
None, ServerBanCommand, ServerBanModule,
|
||||||
ChannelBanCommand, ChannelBanModule, RoleBanCommand,
|
ChannelBanCommand, ChannelBanModule, RoleBanCommand,
|
||||||
RoleBanModule, UserBanCommand, UserBanModule
|
RoleBanModule, UserBanCommand, UserBanModule
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void Initialize() {
|
public static void Initialize()
|
||||||
|
{
|
||||||
Console.WriteLine("Reading from the permission files.");
|
Console.WriteLine("Reading from the permission files.");
|
||||||
Directory.CreateDirectory("data/permissions");
|
Directory.CreateDirectory("data/permissions");
|
||||||
foreach (var file in Directory.EnumerateFiles("data/permissions/")) {
|
foreach (var file in Directory.EnumerateFiles("data/permissions/"))
|
||||||
try {
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
var strippedFileName = Path.GetFileNameWithoutExtension(file);
|
var strippedFileName = Path.GetFileNameWithoutExtension(file);
|
||||||
if (string.IsNullOrWhiteSpace(strippedFileName)) continue;
|
if (string.IsNullOrWhiteSpace(strippedFileName)) continue;
|
||||||
var id = ulong.Parse(strippedFileName);
|
var id = ulong.Parse(strippedFileName);
|
||||||
var data = Newtonsoft.Json.JsonConvert.DeserializeObject<ServerPermissions>(File.ReadAllText(file));
|
var data = Newtonsoft.Json.JsonConvert.DeserializeObject<ServerPermissions>(File.ReadAllText(file));
|
||||||
PermissionsDict.TryAdd(id, data);
|
PermissionsDict.TryAdd(id, data);
|
||||||
} catch { }
|
}
|
||||||
|
catch { }
|
||||||
}
|
}
|
||||||
Console.WriteLine("Permission initialization complete.");
|
Console.WriteLine("Permission initialization complete.");
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static Permissions GetRolePermissionsById(Server server, ulong id) {
|
internal static Permissions GetRolePermissionsById(Server server, ulong id)
|
||||||
|
{
|
||||||
ServerPermissions serverPerms;
|
ServerPermissions serverPerms;
|
||||||
if (!PermissionsDict.TryGetValue(server.Id, out serverPerms))
|
if (!PermissionsDict.TryGetValue(server.Id, out serverPerms))
|
||||||
return null;
|
return null;
|
||||||
@ -44,7 +52,8 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static Permissions GetUserPermissionsById(Server server, ulong id) {
|
internal static Permissions GetUserPermissionsById(Server server, ulong id)
|
||||||
|
{
|
||||||
ServerPermissions serverPerms;
|
ServerPermissions serverPerms;
|
||||||
if (!PermissionsDict.TryGetValue(server.Id, out serverPerms))
|
if (!PermissionsDict.TryGetValue(server.Id, out serverPerms))
|
||||||
return null;
|
return null;
|
||||||
@ -54,7 +63,8 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static Permissions GetChannelPermissionsById(Server server, ulong id) {
|
internal static Permissions GetChannelPermissionsById(Server server, ulong id)
|
||||||
|
{
|
||||||
ServerPermissions serverPerms;
|
ServerPermissions serverPerms;
|
||||||
if (!PermissionsDict.TryGetValue(server.Id, out serverPerms))
|
if (!PermissionsDict.TryGetValue(server.Id, out serverPerms))
|
||||||
return null;
|
return null;
|
||||||
@ -64,12 +74,14 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static Permissions GetServerPermissions(Server server) {
|
internal static Permissions GetServerPermissions(Server server)
|
||||||
|
{
|
||||||
ServerPermissions serverPerms;
|
ServerPermissions serverPerms;
|
||||||
return !PermissionsDict.TryGetValue(server.Id, out serverPerms) ? null : serverPerms.Permissions;
|
return !PermissionsDict.TryGetValue(server.Id, out serverPerms) ? null : serverPerms.Permissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static PermissionBanType GetPermissionBanType(Command command, User user, Channel channel) {
|
internal static PermissionBanType GetPermissionBanType(Command command, User user, Channel channel)
|
||||||
|
{
|
||||||
var server = user.Server;
|
var server = user.Server;
|
||||||
ServerPermissions serverPerms = PermissionsDict.GetOrAdd(server.Id, id => new ServerPermissions(id, server.Name));
|
ServerPermissions serverPerms = PermissionsDict.GetOrAdd(server.Id, id => new ServerPermissions(id, server.Name));
|
||||||
bool val;
|
bool val;
|
||||||
@ -94,7 +106,8 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
// IF AT LEAST ONE ROLE EXIST THAT IS NOT BANNED,
|
// IF AT LEAST ONE ROLE EXIST THAT IS NOT BANNED,
|
||||||
// USER CAN RUN THE COMMAND
|
// USER CAN RUN THE COMMAND
|
||||||
var foundNotBannedRole = false;
|
var foundNotBannedRole = false;
|
||||||
foreach (var role in user.Roles) {
|
foreach (var role in user.Roles)
|
||||||
|
{
|
||||||
//if every role is banned from using the module -> rolebanmodule
|
//if every role is banned from using the module -> rolebanmodule
|
||||||
if (serverPerms.RolePermissions.TryGetValue(role.Id, out perm) &&
|
if (serverPerms.RolePermissions.TryGetValue(role.Id, out perm) &&
|
||||||
perm.Modules.TryGetValue(command.Category, out val) && val == false)
|
perm.Modules.TryGetValue(command.Category, out val) && val == false)
|
||||||
@ -111,12 +124,14 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
// IF AT LEAST ONE ROLE EXISTS THAT IS NOT BANNED,
|
// IF AT LEAST ONE ROLE EXISTS THAT IS NOT BANNED,
|
||||||
// USER CAN RUN THE COMMAND
|
// USER CAN RUN THE COMMAND
|
||||||
foundNotBannedRole = false;
|
foundNotBannedRole = false;
|
||||||
foreach (var role in user.Roles) {
|
foreach (var role in user.Roles)
|
||||||
|
{
|
||||||
//if every role is banned from using the module -> rolebanmodule
|
//if every role is banned from using the module -> rolebanmodule
|
||||||
if (serverPerms.RolePermissions.TryGetValue(role.Id, out perm) &&
|
if (serverPerms.RolePermissions.TryGetValue(role.Id, out perm) &&
|
||||||
perm.Commands.TryGetValue(command.Text, out val) && val == false)
|
perm.Commands.TryGetValue(command.Text, out val) && val == false)
|
||||||
continue;
|
continue;
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
foundNotBannedRole = true;
|
foundNotBannedRole = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -135,27 +150,32 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
return PermissionBanType.None;
|
return PermissionBanType.None;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void WriteServerToJson(ServerPermissions serverPerms) {
|
private static void WriteServerToJson(ServerPermissions serverPerms)
|
||||||
|
{
|
||||||
string pathToFile = $"data/permissions/{serverPerms.Id}.json";
|
string pathToFile = $"data/permissions/{serverPerms.Id}.json";
|
||||||
File.WriteAllText(pathToFile,
|
File.WriteAllText(pathToFile,
|
||||||
Newtonsoft.Json.JsonConvert.SerializeObject(serverPerms, Newtonsoft.Json.Formatting.Indented));
|
Newtonsoft.Json.JsonConvert.SerializeObject(serverPerms, Newtonsoft.Json.Formatting.Indented));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void WriteToJson() {
|
public static void WriteToJson()
|
||||||
|
{
|
||||||
Directory.CreateDirectory("data/permissions/");
|
Directory.CreateDirectory("data/permissions/");
|
||||||
foreach (var kvp in PermissionsDict) {
|
foreach (var kvp in PermissionsDict)
|
||||||
|
{
|
||||||
WriteServerToJson(kvp.Value);
|
WriteServerToJson(kvp.Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetServerPermissionsRoleName(Server server) {
|
public static string GetServerPermissionsRoleName(Server server)
|
||||||
|
{
|
||||||
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
|
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
|
||||||
new ServerPermissions(server.Id, server.Name));
|
new ServerPermissions(server.Id, server.Name));
|
||||||
|
|
||||||
return serverPerms.PermissionsControllerRole;
|
return serverPerms.PermissionsControllerRole;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void SetPermissionsRole(Server server, string roleName) {
|
internal static void SetPermissionsRole(Server server, string roleName)
|
||||||
|
{
|
||||||
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
|
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
|
||||||
new ServerPermissions(server.Id, server.Name));
|
new ServerPermissions(server.Id, server.Name));
|
||||||
|
|
||||||
@ -163,7 +183,8 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
Task.Run(() => WriteServerToJson(serverPerms));
|
Task.Run(() => WriteServerToJson(serverPerms));
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void SetVerbosity(Server server, bool val) {
|
internal static void SetVerbosity(Server server, bool val)
|
||||||
|
{
|
||||||
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
|
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
|
||||||
new ServerPermissions(server.Id, server.Name));
|
new ServerPermissions(server.Id, server.Name));
|
||||||
|
|
||||||
@ -171,7 +192,8 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
Task.Run(() => WriteServerToJson(serverPerms));
|
Task.Run(() => WriteServerToJson(serverPerms));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetServerModulePermission(Server server, string moduleName, bool value) {
|
public static void SetServerModulePermission(Server server, string moduleName, bool value)
|
||||||
|
{
|
||||||
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
|
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
|
||||||
new ServerPermissions(server.Id, server.Name));
|
new ServerPermissions(server.Id, server.Name));
|
||||||
|
|
||||||
@ -183,7 +205,8 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
Task.Run(() => WriteServerToJson(serverPerms));
|
Task.Run(() => WriteServerToJson(serverPerms));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetServerCommandPermission(Server server, string commandName, bool value) {
|
public static void SetServerCommandPermission(Server server, string commandName, bool value)
|
||||||
|
{
|
||||||
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
|
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
|
||||||
new ServerPermissions(server.Id, server.Name));
|
new ServerPermissions(server.Id, server.Name));
|
||||||
|
|
||||||
@ -195,7 +218,8 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
Task.Run(() => WriteServerToJson(serverPerms));
|
Task.Run(() => WriteServerToJson(serverPerms));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetChannelModulePermission(Channel channel, string moduleName, bool value) {
|
public static void SetChannelModulePermission(Channel channel, string moduleName, bool value)
|
||||||
|
{
|
||||||
var server = channel.Server;
|
var server = channel.Server;
|
||||||
|
|
||||||
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
|
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
|
||||||
@ -213,7 +237,8 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
Task.Run(() => WriteServerToJson(serverPerms));
|
Task.Run(() => WriteServerToJson(serverPerms));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetChannelCommandPermission(Channel channel, string commandName, bool value) {
|
public static void SetChannelCommandPermission(Channel channel, string commandName, bool value)
|
||||||
|
{
|
||||||
var server = channel.Server;
|
var server = channel.Server;
|
||||||
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
|
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
|
||||||
new ServerPermissions(server.Id, server.Name));
|
new ServerPermissions(server.Id, server.Name));
|
||||||
@ -230,7 +255,8 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
Task.Run(() => WriteServerToJson(serverPerms));
|
Task.Run(() => WriteServerToJson(serverPerms));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetRoleModulePermission(Role role, string moduleName, bool value) {
|
public static void SetRoleModulePermission(Role role, string moduleName, bool value)
|
||||||
|
{
|
||||||
var server = role.Server;
|
var server = role.Server;
|
||||||
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
|
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
|
||||||
new ServerPermissions(server.Id, server.Name));
|
new ServerPermissions(server.Id, server.Name));
|
||||||
@ -247,7 +273,8 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
Task.Run(() => WriteServerToJson(serverPerms));
|
Task.Run(() => WriteServerToJson(serverPerms));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetRoleCommandPermission(Role role, string commandName, bool value) {
|
public static void SetRoleCommandPermission(Role role, string commandName, bool value)
|
||||||
|
{
|
||||||
var server = role.Server;
|
var server = role.Server;
|
||||||
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
|
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
|
||||||
new ServerPermissions(server.Id, server.Name));
|
new ServerPermissions(server.Id, server.Name));
|
||||||
@ -264,7 +291,8 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
Task.Run(() => WriteServerToJson(serverPerms));
|
Task.Run(() => WriteServerToJson(serverPerms));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetUserModulePermission(User user, string moduleName, bool value) {
|
public static void SetUserModulePermission(User user, string moduleName, bool value)
|
||||||
|
{
|
||||||
var server = user.Server;
|
var server = user.Server;
|
||||||
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
|
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
|
||||||
new ServerPermissions(server.Id, server.Name));
|
new ServerPermissions(server.Id, server.Name));
|
||||||
@ -281,7 +309,8 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
Task.Run(() => WriteServerToJson(serverPerms));
|
Task.Run(() => WriteServerToJson(serverPerms));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetUserCommandPermission(User user, string commandName, bool value) {
|
public static void SetUserCommandPermission(User user, string commandName, bool value)
|
||||||
|
{
|
||||||
var server = user.Server;
|
var server = user.Server;
|
||||||
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
|
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
|
||||||
new ServerPermissions(server.Id, server.Name));
|
new ServerPermissions(server.Id, server.Name));
|
||||||
@ -297,7 +326,8 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
Task.Run(() => WriteServerToJson(serverPerms));
|
Task.Run(() => WriteServerToJson(serverPerms));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetServerWordPermission(Server server, bool value) {
|
public static void SetServerWordPermission(Server server, bool value)
|
||||||
|
{
|
||||||
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
|
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
|
||||||
new ServerPermissions(server.Id, server.Name));
|
new ServerPermissions(server.Id, server.Name));
|
||||||
|
|
||||||
@ -305,7 +335,8 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
Task.Run(() => WriteServerToJson(serverPerms));
|
Task.Run(() => WriteServerToJson(serverPerms));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetChannelWordPermission(Channel channel, bool value) {
|
public static void SetChannelWordPermission(Channel channel, bool value)
|
||||||
|
{
|
||||||
var server = channel.Server;
|
var server = channel.Server;
|
||||||
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
|
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
|
||||||
new ServerPermissions(server.Id, server.Name));
|
new ServerPermissions(server.Id, server.Name));
|
||||||
@ -317,7 +348,8 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
Task.Run(() => WriteServerToJson(serverPerms));
|
Task.Run(() => WriteServerToJson(serverPerms));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetServerFilterInvitesPermission(Server server, bool value) {
|
public static void SetServerFilterInvitesPermission(Server server, bool value)
|
||||||
|
{
|
||||||
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
|
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
|
||||||
new ServerPermissions(server.Id, server.Name));
|
new ServerPermissions(server.Id, server.Name));
|
||||||
|
|
||||||
@ -325,7 +357,8 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
Task.Run(() => WriteServerToJson(serverPerms));
|
Task.Run(() => WriteServerToJson(serverPerms));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetChannelFilterInvitesPermission(Channel channel, bool value) {
|
public static void SetChannelFilterInvitesPermission(Channel channel, bool value)
|
||||||
|
{
|
||||||
var server = channel.Server;
|
var server = channel.Server;
|
||||||
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
|
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
|
||||||
new ServerPermissions(server.Id, server.Name));
|
new ServerPermissions(server.Id, server.Name));
|
||||||
@ -337,7 +370,8 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
Task.Run(() => WriteServerToJson(serverPerms));
|
Task.Run(() => WriteServerToJson(serverPerms));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AddFilteredWord(Server server, string word) {
|
public static void AddFilteredWord(Server server, string word)
|
||||||
|
{
|
||||||
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
|
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
|
||||||
new ServerPermissions(server.Id, server.Name));
|
new ServerPermissions(server.Id, server.Name));
|
||||||
if (serverPerms.Words.Contains(word))
|
if (serverPerms.Words.Contains(word))
|
||||||
@ -345,7 +379,8 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
serverPerms.Words.Add(word);
|
serverPerms.Words.Add(word);
|
||||||
Task.Run(() => WriteServerToJson(serverPerms));
|
Task.Run(() => WriteServerToJson(serverPerms));
|
||||||
}
|
}
|
||||||
public static void RemoveFilteredWord(Server server, string word) {
|
public static void RemoveFilteredWord(Server server, string word)
|
||||||
|
{
|
||||||
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
|
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
|
||||||
new ServerPermissions(server.Id, server.Name));
|
new ServerPermissions(server.Id, server.Name));
|
||||||
if (!serverPerms.Words.Contains(word))
|
if (!serverPerms.Words.Contains(word))
|
||||||
@ -357,7 +392,8 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Holds a permission list
|
/// Holds a permission list
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Permissions {
|
public class Permissions
|
||||||
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Name of the parent object whose permissions these are
|
/// Name of the parent object whose permissions these are
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -379,7 +415,8 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool FilterWords { get; set; }
|
public bool FilterWords { get; set; }
|
||||||
|
|
||||||
public Permissions(string name) {
|
public Permissions(string name)
|
||||||
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
Modules = new ConcurrentDictionary<string, bool>();
|
Modules = new ConcurrentDictionary<string, bool>();
|
||||||
Commands = new ConcurrentDictionary<string, bool>();
|
Commands = new ConcurrentDictionary<string, bool>();
|
||||||
@ -387,17 +424,20 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
FilterWords = false;
|
FilterWords = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString() {
|
public override string ToString()
|
||||||
|
{
|
||||||
var toReturn = "";
|
var toReturn = "";
|
||||||
var bannedModules = Modules.Where(kvp => kvp.Value == false);
|
var bannedModules = Modules.Where(kvp => kvp.Value == false);
|
||||||
var bannedModulesArray = bannedModules as KeyValuePair<string, bool>[] ?? bannedModules.ToArray();
|
var bannedModulesArray = bannedModules as KeyValuePair<string, bool>[] ?? bannedModules.ToArray();
|
||||||
if (bannedModulesArray.Any()) {
|
if (bannedModulesArray.Any())
|
||||||
|
{
|
||||||
toReturn += "`Banned Modules:`\n";
|
toReturn += "`Banned Modules:`\n";
|
||||||
toReturn = bannedModulesArray.Aggregate(toReturn, (current, m) => current + $"\t`[x] {m.Key}`\n");
|
toReturn = bannedModulesArray.Aggregate(toReturn, (current, m) => current + $"\t`[x] {m.Key}`\n");
|
||||||
}
|
}
|
||||||
var bannedCommands = Commands.Where(kvp => kvp.Value == false);
|
var bannedCommands = Commands.Where(kvp => kvp.Value == false);
|
||||||
var bannedCommandsArr = bannedCommands as KeyValuePair<string, bool>[] ?? bannedCommands.ToArray();
|
var bannedCommandsArr = bannedCommands as KeyValuePair<string, bool>[] ?? bannedCommands.ToArray();
|
||||||
if (bannedCommandsArr.Any()) {
|
if (bannedCommandsArr.Any())
|
||||||
|
{
|
||||||
toReturn += "`Banned Commands:`\n";
|
toReturn += "`Banned Commands:`\n";
|
||||||
toReturn = bannedCommandsArr.Aggregate(toReturn, (current, c) => current + $"\t`[x] {c.Key}`\n");
|
toReturn = bannedCommandsArr.Aggregate(toReturn, (current, c) => current + $"\t`[x] {c.Key}`\n");
|
||||||
}
|
}
|
||||||
@ -405,7 +445,8 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ServerPermissions {
|
public class ServerPermissions
|
||||||
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The guy who can edit the permissions
|
/// The guy who can edit the permissions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -431,7 +472,8 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
public Dictionary<ulong, Permissions> ChannelPermissions { get; set; }
|
public Dictionary<ulong, Permissions> ChannelPermissions { get; set; }
|
||||||
public Dictionary<ulong, Permissions> RolePermissions { get; set; }
|
public Dictionary<ulong, Permissions> RolePermissions { get; set; }
|
||||||
|
|
||||||
public ServerPermissions(ulong id, string name) {
|
public ServerPermissions(ulong id, string name)
|
||||||
|
{
|
||||||
Id = id;
|
Id = id;
|
||||||
PermissionsControllerRole = "Nadeko";
|
PermissionsControllerRole = "Nadeko";
|
||||||
Verbose = true;
|
Verbose = true;
|
@ -1,10 +1,12 @@
|
|||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using System;
|
|
||||||
using Discord.Commands.Permissions;
|
using Discord.Commands.Permissions;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace NadekoBot.Classes.Permissions {
|
namespace NadekoBot.Modules.Permissions.Classes
|
||||||
public static class SimpleCheckers {
|
{
|
||||||
|
public static class SimpleCheckers
|
||||||
|
{
|
||||||
public static ManageRoles CanManageRoles { get; } = new ManageRoles();
|
public static ManageRoles CanManageRoles { get; } = new ManageRoles();
|
||||||
|
|
||||||
public static Func<Command, User, Channel, bool> OwnerOnly() =>
|
public static Func<Command, User, Channel, bool> OwnerOnly() =>
|
||||||
@ -19,8 +21,10 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
public static Func<Command, User, Channel, bool> ManageServer() =>
|
public static Func<Command, User, Channel, bool> ManageServer() =>
|
||||||
(com, user, ch) => user.ServerPermissions.ManageServer;
|
(com, user, ch) => user.ServerPermissions.ManageServer;
|
||||||
|
|
||||||
public class ManageRoles : IPermissionChecker {
|
public class ManageRoles : IPermissionChecker
|
||||||
public bool CanRun(Command command, User user, Channel channel, out string error) {
|
{
|
||||||
|
public bool CanRun(Command command, User user, Channel channel, out string error)
|
||||||
|
{
|
||||||
error = string.Empty;
|
error = string.Empty;
|
||||||
if (user.ServerPermissions.ManageRoles)
|
if (user.ServerPermissions.ManageRoles)
|
||||||
return true;
|
return true;
|
@ -1,11 +1,10 @@
|
|||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using NadekoBot.Classes;
|
using NadekoBot.Classes;
|
||||||
using NadekoBot.Classes.Permissions;
|
using NadekoBot.Classes;
|
||||||
using NadekoBot.Commands;
|
using NadekoBot.Modules.Permissions.Classes;
|
||||||
using System;
|
using System;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using ServerPermissions = NadekoBot.Classes.Permissions.ServerPermissions;
|
|
||||||
|
|
||||||
namespace NadekoBot.Modules.Permissions.Commands
|
namespace NadekoBot.Modules.Permissions.Commands
|
||||||
{
|
{
|
||||||
@ -21,7 +20,7 @@ namespace NadekoBot.Modules.Permissions.Commands
|
|||||||
if (args.Channel.IsPrivate || args.User.Id == NadekoBot.Client.CurrentUser.Id) return;
|
if (args.Channel.IsPrivate || args.User.Id == NadekoBot.Client.CurrentUser.Id) return;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ServerPermissions serverPerms;
|
Classes.ServerPermissions serverPerms;
|
||||||
if (!IsChannelOrServerFiltering(args.Channel, out serverPerms)) return;
|
if (!IsChannelOrServerFiltering(args.Channel, out serverPerms)) return;
|
||||||
|
|
||||||
if (filterRegex.IsMatch(args.Message.RawText))
|
if (filterRegex.IsMatch(args.Message.RawText))
|
||||||
@ -39,14 +38,14 @@ namespace NadekoBot.Modules.Permissions.Commands
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool IsChannelOrServerFiltering(Channel channel, out ServerPermissions serverPerms)
|
private static bool IsChannelOrServerFiltering(Channel channel, out Classes.ServerPermissions serverPerms)
|
||||||
{
|
{
|
||||||
if (!PermissionsHandler.PermissionsDict.TryGetValue(channel.Server.Id, out serverPerms)) return false;
|
if (!PermissionsHandler.PermissionsDict.TryGetValue(channel.Server.Id, out serverPerms)) return false;
|
||||||
|
|
||||||
if (serverPerms.Permissions.FilterInvites)
|
if (serverPerms.Permissions.FilterInvites)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
Classes.Permissions.Permissions perms;
|
Classes.Permissions perms;
|
||||||
return serverPerms.ChannelPermissions.TryGetValue(channel.Id, out perms) && perms.FilterInvites;
|
return serverPerms.ChannelPermissions.TryGetValue(channel.Id, out perms) && perms.FilterInvites;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using NadekoBot.Classes;
|
using NadekoBot.Classes;
|
||||||
using NadekoBot.Classes.Permissions;
|
using NadekoBot.Classes;
|
||||||
using NadekoBot.Commands;
|
using NadekoBot.Modules.Permissions.Classes;
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using ServerPermissions = NadekoBot.Classes.Permissions.ServerPermissions;
|
|
||||||
|
|
||||||
namespace NadekoBot.Modules.Permissions.Commands
|
namespace NadekoBot.Modules.Permissions.Commands
|
||||||
{
|
{
|
||||||
@ -18,7 +17,7 @@ namespace NadekoBot.Modules.Permissions.Commands
|
|||||||
if (args.Channel.IsPrivate || args.User.Id == NadekoBot.Client.CurrentUser.Id) return;
|
if (args.Channel.IsPrivate || args.User.Id == NadekoBot.Client.CurrentUser.Id) return;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ServerPermissions serverPerms;
|
Classes.ServerPermissions serverPerms;
|
||||||
if (!IsChannelOrServerFiltering(args.Channel, out serverPerms)) return;
|
if (!IsChannelOrServerFiltering(args.Channel, out serverPerms)) return;
|
||||||
|
|
||||||
var wordsInMessage = args.Message.RawText.ToLowerInvariant().Split(' ');
|
var wordsInMessage = args.Message.RawText.ToLowerInvariant().Split(' ');
|
||||||
@ -37,14 +36,14 @@ namespace NadekoBot.Modules.Permissions.Commands
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool IsChannelOrServerFiltering(Channel channel, out ServerPermissions serverPerms)
|
private static bool IsChannelOrServerFiltering(Channel channel, out Classes.ServerPermissions serverPerms)
|
||||||
{
|
{
|
||||||
if (!PermissionsHandler.PermissionsDict.TryGetValue(channel.Server.Id, out serverPerms)) return false;
|
if (!PermissionsHandler.PermissionsDict.TryGetValue(channel.Server.Id, out serverPerms)) return false;
|
||||||
|
|
||||||
if (serverPerms.Permissions.FilterWords)
|
if (serverPerms.Permissions.FilterWords)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
Classes.Permissions.Permissions perms;
|
Classes.Permissions perms;
|
||||||
return serverPerms.ChannelPermissions.TryGetValue(channel.Id, out perms) && perms.FilterWords;
|
return serverPerms.ChannelPermissions.TryGetValue(channel.Id, out perms) && perms.FilterWords;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,7 +138,7 @@ namespace NadekoBot.Modules.Permissions.Commands
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ServerPermissions serverPerms;
|
Classes.ServerPermissions serverPerms;
|
||||||
if (!PermissionsHandler.PermissionsDict.TryGetValue(e.Server.Id, out serverPerms))
|
if (!PermissionsHandler.PermissionsDict.TryGetValue(e.Server.Id, out serverPerms))
|
||||||
return;
|
return;
|
||||||
await e.Channel.SendMessage($"There are `{serverPerms.Words.Count}` filtered words.\n" +
|
await e.Channel.SendMessage($"There are `{serverPerms.Words.Count}` filtered words.\n" +
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Discord.Modules;
|
using Discord.Modules;
|
||||||
using NadekoBot.Classes.JSONModels;
|
using NadekoBot.Classes.JSONModels;
|
||||||
using NadekoBot.Classes.Permissions;
|
|
||||||
using NadekoBot.Extensions;
|
using NadekoBot.Extensions;
|
||||||
using NadekoBot.Modules.Games.Commands;
|
using NadekoBot.Modules.Games.Commands;
|
||||||
|
using NadekoBot.Modules.Permissions.Classes;
|
||||||
using NadekoBot.Modules.Permissions.Commands;
|
using NadekoBot.Modules.Permissions.Commands;
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using PermsHandler = NadekoBot.Classes.Permissions.PermissionsHandler;
|
|
||||||
|
|
||||||
namespace NadekoBot.Modules.Permissions
|
namespace NadekoBot.Modules.Permissions
|
||||||
{
|
{
|
||||||
@ -39,7 +38,7 @@ namespace NadekoBot.Modules.Permissions
|
|||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(e.GetArg("role")))
|
if (string.IsNullOrWhiteSpace(e.GetArg("role")))
|
||||||
{
|
{
|
||||||
await e.Channel.SendMessage($"Current permissions role is `{PermsHandler.GetServerPermissionsRoleName(e.Server)}`");
|
await e.Channel.SendMessage($"Current permissions role is `{PermissionsHandler.GetServerPermissionsRoleName(e.Server)}`");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,7 +54,7 @@ namespace NadekoBot.Modules.Permissions
|
|||||||
await e.Channel.SendMessage($"Role `{arg}` probably doesn't exist. Create the role with that name first.");
|
await e.Channel.SendMessage($"Role `{arg}` probably doesn't exist. Create the role with that name first.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PermsHandler.SetPermissionsRole(e.Server, role.Name);
|
PermissionsHandler.SetPermissionsRole(e.Server, role.Name);
|
||||||
await e.Channel.SendMessage($"Role `{role.Name}` is now required in order to change permissions.");
|
await e.Channel.SendMessage($"Role `{role.Name}` is now required in order to change permissions.");
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -67,7 +66,7 @@ namespace NadekoBot.Modules.Permissions
|
|||||||
{
|
{
|
||||||
var arg = e.GetArg("arg");
|
var arg = e.GetArg("arg");
|
||||||
var val = PermissionHelper.ValidateBool(arg);
|
var val = PermissionHelper.ValidateBool(arg);
|
||||||
PermsHandler.SetVerbosity(e.Server, val);
|
PermissionsHandler.SetVerbosity(e.Server, val);
|
||||||
await e.Channel.SendMessage($"Verbosity set to {val}.");
|
await e.Channel.SendMessage($"Verbosity set to {val}.");
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -76,7 +75,7 @@ namespace NadekoBot.Modules.Permissions
|
|||||||
.Description("Shows banned permissions for this server.")
|
.Description("Shows banned permissions for this server.")
|
||||||
.Do(async e =>
|
.Do(async e =>
|
||||||
{
|
{
|
||||||
var perms = PermsHandler.GetServerPermissions(e.Server);
|
var perms = PermissionsHandler.GetServerPermissions(e.Server);
|
||||||
if (string.IsNullOrWhiteSpace(perms?.ToString()))
|
if (string.IsNullOrWhiteSpace(perms?.ToString()))
|
||||||
await e.Channel.SendMessage("No permissions set for this server.");
|
await e.Channel.SendMessage("No permissions set for this server.");
|
||||||
await e.Channel.SendMessage(perms.ToString());
|
await e.Channel.SendMessage(perms.ToString());
|
||||||
@ -101,7 +100,7 @@ namespace NadekoBot.Modules.Permissions
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var perms = PermsHandler.GetRolePermissionsById(e.Server, role.Id);
|
var perms = PermissionsHandler.GetRolePermissionsById(e.Server, role.Id);
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(perms?.ToString()))
|
if (string.IsNullOrWhiteSpace(perms?.ToString()))
|
||||||
await e.Channel.SendMessage($"No permissions set for **{role.Name}** role.");
|
await e.Channel.SendMessage($"No permissions set for **{role.Name}** role.");
|
||||||
@ -127,7 +126,7 @@ namespace NadekoBot.Modules.Permissions
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var perms = PermsHandler.GetChannelPermissionsById(e.Server, channel.Id);
|
var perms = PermissionsHandler.GetChannelPermissionsById(e.Server, channel.Id);
|
||||||
if (string.IsNullOrWhiteSpace(perms?.ToString()))
|
if (string.IsNullOrWhiteSpace(perms?.ToString()))
|
||||||
await e.Channel.SendMessage($"No permissions set for **{channel.Name}** channel.");
|
await e.Channel.SendMessage($"No permissions set for **{channel.Name}** channel.");
|
||||||
await e.Channel.SendMessage(perms.ToString());
|
await e.Channel.SendMessage(perms.ToString());
|
||||||
@ -151,7 +150,7 @@ namespace NadekoBot.Modules.Permissions
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var perms = PermsHandler.GetUserPermissionsById(e.Server, user.Id);
|
var perms = PermissionsHandler.GetUserPermissionsById(e.Server, user.Id);
|
||||||
if (string.IsNullOrWhiteSpace(perms?.ToString()))
|
if (string.IsNullOrWhiteSpace(perms?.ToString()))
|
||||||
await e.Channel.SendMessage($"No permissions set for user **{user.Name}**.");
|
await e.Channel.SendMessage($"No permissions set for user **{user.Name}**.");
|
||||||
await e.Channel.SendMessage(perms.ToString());
|
await e.Channel.SendMessage(perms.ToString());
|
||||||
@ -168,7 +167,7 @@ namespace NadekoBot.Modules.Permissions
|
|||||||
var module = PermissionHelper.ValidateModule(e.GetArg("module"));
|
var module = PermissionHelper.ValidateModule(e.GetArg("module"));
|
||||||
var state = PermissionHelper.ValidateBool(e.GetArg("bool"));
|
var state = PermissionHelper.ValidateBool(e.GetArg("bool"));
|
||||||
|
|
||||||
PermsHandler.SetServerModulePermission(e.Server, module, state);
|
PermissionsHandler.SetServerModulePermission(e.Server, module, state);
|
||||||
await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** on this server.");
|
await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** on this server.");
|
||||||
}
|
}
|
||||||
catch (ArgumentException exArg)
|
catch (ArgumentException exArg)
|
||||||
@ -192,7 +191,7 @@ namespace NadekoBot.Modules.Permissions
|
|||||||
var command = PermissionHelper.ValidateCommand(e.GetArg("command"));
|
var command = PermissionHelper.ValidateCommand(e.GetArg("command"));
|
||||||
var state = PermissionHelper.ValidateBool(e.GetArg("bool"));
|
var state = PermissionHelper.ValidateBool(e.GetArg("bool"));
|
||||||
|
|
||||||
PermsHandler.SetServerCommandPermission(e.Server, command, state);
|
PermissionsHandler.SetServerCommandPermission(e.Server, command, state);
|
||||||
await e.Channel.SendMessage($"Command **{command}** has been **{(state ? "enabled" : "disabled")}** on this server.");
|
await e.Channel.SendMessage($"Command **{command}** has been **{(state ? "enabled" : "disabled")}** on this server.");
|
||||||
}
|
}
|
||||||
catch (ArgumentException exArg)
|
catch (ArgumentException exArg)
|
||||||
@ -221,7 +220,7 @@ namespace NadekoBot.Modules.Permissions
|
|||||||
{
|
{
|
||||||
foreach (var role in e.Server.Roles)
|
foreach (var role in e.Server.Roles)
|
||||||
{
|
{
|
||||||
PermsHandler.SetRoleModulePermission(role, module, state);
|
PermissionsHandler.SetRoleModulePermission(role, module, state);
|
||||||
}
|
}
|
||||||
await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** for **ALL** roles.");
|
await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** for **ALL** roles.");
|
||||||
}
|
}
|
||||||
@ -229,7 +228,7 @@ namespace NadekoBot.Modules.Permissions
|
|||||||
{
|
{
|
||||||
var role = PermissionHelper.ValidateRole(e.Server, e.GetArg("role"));
|
var role = PermissionHelper.ValidateRole(e.Server, e.GetArg("role"));
|
||||||
|
|
||||||
PermsHandler.SetRoleModulePermission(role, module, state);
|
PermissionsHandler.SetRoleModulePermission(role, module, state);
|
||||||
await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** for **{role.Name}** role.");
|
await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** for **{role.Name}** role.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -259,7 +258,7 @@ namespace NadekoBot.Modules.Permissions
|
|||||||
{
|
{
|
||||||
foreach (var role in e.Server.Roles)
|
foreach (var role in e.Server.Roles)
|
||||||
{
|
{
|
||||||
PermsHandler.SetRoleCommandPermission(role, command, state);
|
PermissionsHandler.SetRoleCommandPermission(role, command, state);
|
||||||
}
|
}
|
||||||
await e.Channel.SendMessage($"Command **{command}** has been **{(state ? "enabled" : "disabled")}** for **ALL** roles.");
|
await e.Channel.SendMessage($"Command **{command}** has been **{(state ? "enabled" : "disabled")}** for **ALL** roles.");
|
||||||
}
|
}
|
||||||
@ -267,7 +266,7 @@ namespace NadekoBot.Modules.Permissions
|
|||||||
{
|
{
|
||||||
var role = PermissionHelper.ValidateRole(e.Server, e.GetArg("role"));
|
var role = PermissionHelper.ValidateRole(e.Server, e.GetArg("role"));
|
||||||
|
|
||||||
PermsHandler.SetRoleCommandPermission(role, command, state);
|
PermissionsHandler.SetRoleCommandPermission(role, command, state);
|
||||||
await e.Channel.SendMessage($"Command **{command}** has been **{(state ? "enabled" : "disabled")}** for **{role.Name}** role.");
|
await e.Channel.SendMessage($"Command **{command}** has been **{(state ? "enabled" : "disabled")}** for **{role.Name}** role.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -297,7 +296,7 @@ namespace NadekoBot.Modules.Permissions
|
|||||||
{
|
{
|
||||||
foreach (var channel in e.Server.TextChannels)
|
foreach (var channel in e.Server.TextChannels)
|
||||||
{
|
{
|
||||||
PermsHandler.SetChannelModulePermission(channel, module, state);
|
PermissionsHandler.SetChannelModulePermission(channel, module, state);
|
||||||
}
|
}
|
||||||
await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** on **ALL** channels.");
|
await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** on **ALL** channels.");
|
||||||
}
|
}
|
||||||
@ -305,7 +304,7 @@ namespace NadekoBot.Modules.Permissions
|
|||||||
{
|
{
|
||||||
var channel = PermissionHelper.ValidateChannel(e.Server, e.GetArg("channel"));
|
var channel = PermissionHelper.ValidateChannel(e.Server, e.GetArg("channel"));
|
||||||
|
|
||||||
PermsHandler.SetChannelModulePermission(channel, module, state);
|
PermissionsHandler.SetChannelModulePermission(channel, module, state);
|
||||||
await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** for **{channel.Name}** channel.");
|
await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** for **{channel.Name}** channel.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -335,7 +334,7 @@ namespace NadekoBot.Modules.Permissions
|
|||||||
{
|
{
|
||||||
foreach (var channel in e.Server.TextChannels)
|
foreach (var channel in e.Server.TextChannels)
|
||||||
{
|
{
|
||||||
PermsHandler.SetChannelCommandPermission(channel, command, state);
|
PermissionsHandler.SetChannelCommandPermission(channel, command, state);
|
||||||
}
|
}
|
||||||
await e.Channel.SendMessage($"Command **{command}** has been **{(state ? "enabled" : "disabled")}** on **ALL** channels.");
|
await e.Channel.SendMessage($"Command **{command}** has been **{(state ? "enabled" : "disabled")}** on **ALL** channels.");
|
||||||
}
|
}
|
||||||
@ -343,7 +342,7 @@ namespace NadekoBot.Modules.Permissions
|
|||||||
{
|
{
|
||||||
var channel = PermissionHelper.ValidateChannel(e.Server, e.GetArg("channel"));
|
var channel = PermissionHelper.ValidateChannel(e.Server, e.GetArg("channel"));
|
||||||
|
|
||||||
PermsHandler.SetChannelCommandPermission(channel, command, state);
|
PermissionsHandler.SetChannelCommandPermission(channel, command, state);
|
||||||
await e.Channel.SendMessage($"Command **{command}** has been **{(state ? "enabled" : "disabled")}** for **{channel.Name}** channel.");
|
await e.Channel.SendMessage($"Command **{command}** has been **{(state ? "enabled" : "disabled")}** for **{channel.Name}** channel.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -370,7 +369,7 @@ namespace NadekoBot.Modules.Permissions
|
|||||||
var state = PermissionHelper.ValidateBool(e.GetArg("bool"));
|
var state = PermissionHelper.ValidateBool(e.GetArg("bool"));
|
||||||
var user = PermissionHelper.ValidateUser(e.Server, e.GetArg("user"));
|
var user = PermissionHelper.ValidateUser(e.Server, e.GetArg("user"));
|
||||||
|
|
||||||
PermsHandler.SetUserModulePermission(user, module, state);
|
PermissionsHandler.SetUserModulePermission(user, module, state);
|
||||||
await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** for user **{user.Name}**.");
|
await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** for user **{user.Name}**.");
|
||||||
}
|
}
|
||||||
catch (ArgumentException exArg)
|
catch (ArgumentException exArg)
|
||||||
@ -396,7 +395,7 @@ namespace NadekoBot.Modules.Permissions
|
|||||||
var state = PermissionHelper.ValidateBool(e.GetArg("bool"));
|
var state = PermissionHelper.ValidateBool(e.GetArg("bool"));
|
||||||
var user = PermissionHelper.ValidateUser(e.Server, e.GetArg("user"));
|
var user = PermissionHelper.ValidateUser(e.Server, e.GetArg("user"));
|
||||||
|
|
||||||
PermsHandler.SetUserCommandPermission(user, command, state);
|
PermissionsHandler.SetUserCommandPermission(user, command, state);
|
||||||
await e.Channel.SendMessage($"Command **{command}** has been **{(state ? "enabled" : "disabled")}** for user **{user.Name}**.");
|
await e.Channel.SendMessage($"Command **{command}** has been **{(state ? "enabled" : "disabled")}** for user **{user.Name}**.");
|
||||||
}
|
}
|
||||||
catch (ArgumentException exArg)
|
catch (ArgumentException exArg)
|
||||||
@ -420,7 +419,7 @@ namespace NadekoBot.Modules.Permissions
|
|||||||
|
|
||||||
foreach (var module in NadekoBot.Client.GetService<ModuleService>().Modules)
|
foreach (var module in NadekoBot.Client.GetService<ModuleService>().Modules)
|
||||||
{
|
{
|
||||||
PermsHandler.SetServerModulePermission(e.Server, module.Name, state);
|
PermissionsHandler.SetServerModulePermission(e.Server, module.Name, state);
|
||||||
}
|
}
|
||||||
await e.Channel.SendMessage($"All modules have been **{(state ? "enabled" : "disabled")}** on this server.");
|
await e.Channel.SendMessage($"All modules have been **{(state ? "enabled" : "disabled")}** on this server.");
|
||||||
}
|
}
|
||||||
@ -447,7 +446,7 @@ namespace NadekoBot.Modules.Permissions
|
|||||||
|
|
||||||
foreach (var command in NadekoBot.Client.GetService<CommandService>().AllCommands.Where(c => c.Category == module))
|
foreach (var command in NadekoBot.Client.GetService<CommandService>().AllCommands.Where(c => c.Category == module))
|
||||||
{
|
{
|
||||||
PermsHandler.SetServerCommandPermission(e.Server, command.Text, state);
|
PermissionsHandler.SetServerCommandPermission(e.Server, command.Text, state);
|
||||||
}
|
}
|
||||||
await e.Channel.SendMessage($"All commands from the **{module}** module have been **{(state ? "enabled" : "disabled")}** on this server.");
|
await e.Channel.SendMessage($"All commands from the **{module}** module have been **{(state ? "enabled" : "disabled")}** on this server.");
|
||||||
}
|
}
|
||||||
@ -473,7 +472,7 @@ namespace NadekoBot.Modules.Permissions
|
|||||||
var channel = PermissionHelper.ValidateChannel(e.Server, e.GetArg("channel"));
|
var channel = PermissionHelper.ValidateChannel(e.Server, e.GetArg("channel"));
|
||||||
foreach (var module in NadekoBot.Client.GetService<ModuleService>().Modules)
|
foreach (var module in NadekoBot.Client.GetService<ModuleService>().Modules)
|
||||||
{
|
{
|
||||||
PermsHandler.SetChannelModulePermission(channel, module.Name, state);
|
PermissionsHandler.SetChannelModulePermission(channel, module.Name, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
await e.Channel.SendMessage($"All modules have been **{(state ? "enabled" : "disabled")}** for **{channel.Name}** channel.");
|
await e.Channel.SendMessage($"All modules have been **{(state ? "enabled" : "disabled")}** for **{channel.Name}** channel.");
|
||||||
@ -502,7 +501,7 @@ namespace NadekoBot.Modules.Permissions
|
|||||||
var channel = PermissionHelper.ValidateChannel(e.Server, e.GetArg("channel"));
|
var channel = PermissionHelper.ValidateChannel(e.Server, e.GetArg("channel"));
|
||||||
foreach (var command in NadekoBot.Client.GetService<CommandService>().AllCommands.Where(c => c.Category == module))
|
foreach (var command in NadekoBot.Client.GetService<CommandService>().AllCommands.Where(c => c.Category == module))
|
||||||
{
|
{
|
||||||
PermsHandler.SetChannelCommandPermission(channel, command.Text, state);
|
PermissionsHandler.SetChannelCommandPermission(channel, command.Text, state);
|
||||||
}
|
}
|
||||||
await e.Channel.SendMessage($"All commands from the **{module}** module have been **{(state ? "enabled" : "disabled")}** for **{channel.Name}** channel.");
|
await e.Channel.SendMessage($"All commands from the **{module}** module have been **{(state ? "enabled" : "disabled")}** for **{channel.Name}** channel.");
|
||||||
}
|
}
|
||||||
@ -528,7 +527,7 @@ namespace NadekoBot.Modules.Permissions
|
|||||||
var role = PermissionHelper.ValidateRole(e.Server, e.GetArg("role"));
|
var role = PermissionHelper.ValidateRole(e.Server, e.GetArg("role"));
|
||||||
foreach (var module in NadekoBot.Client.GetService<ModuleService>().Modules)
|
foreach (var module in NadekoBot.Client.GetService<ModuleService>().Modules)
|
||||||
{
|
{
|
||||||
PermsHandler.SetRoleModulePermission(role, module.Name, state);
|
PermissionsHandler.SetRoleModulePermission(role, module.Name, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
await e.Channel.SendMessage($"All modules have been **{(state ? "enabled" : "disabled")}** for **{role.Name}** role.");
|
await e.Channel.SendMessage($"All modules have been **{(state ? "enabled" : "disabled")}** for **{role.Name}** role.");
|
||||||
@ -557,7 +556,7 @@ namespace NadekoBot.Modules.Permissions
|
|||||||
var role = PermissionHelper.ValidateRole(e.Server, e.GetArg("channel"));
|
var role = PermissionHelper.ValidateRole(e.Server, e.GetArg("channel"));
|
||||||
foreach (var command in NadekoBot.Client.GetService<CommandService>().AllCommands.Where(c => c.Category == module))
|
foreach (var command in NadekoBot.Client.GetService<CommandService>().AllCommands.Where(c => c.Category == module))
|
||||||
{
|
{
|
||||||
PermsHandler.SetRoleCommandPermission(role, command.Text, state);
|
PermissionsHandler.SetRoleCommandPermission(role, command.Text, state);
|
||||||
}
|
}
|
||||||
await e.Channel.SendMessage($"All commands from the **{module}** module have been **{(state ? "enabled" : "disabled")}** for **{role.Name}** role.");
|
await e.Channel.SendMessage($"All commands from the **{module}** module have been **{(state ? "enabled" : "disabled")}** for **{role.Name}** role.");
|
||||||
}
|
}
|
||||||
@ -662,8 +661,8 @@ namespace NadekoBot.Modules.Permissions
|
|||||||
NadekoBot.Config.ServerBlacklist.Add(serverId);
|
NadekoBot.Config.ServerBlacklist.Add(serverId);
|
||||||
ConfigHandler.SaveConfig();
|
ConfigHandler.SaveConfig();
|
||||||
//cleanup trivias and typeracing
|
//cleanup trivias and typeracing
|
||||||
Classes.Trivia.TriviaGame trivia;
|
Modules.Games.Commands.Trivia.TriviaGame trivia;
|
||||||
Trivia.RunningTrivias.TryRemove(serverId, out trivia);
|
TriviaCommands.RunningTrivias.TryRemove(serverId, out trivia);
|
||||||
TypingGame typeracer;
|
TypingGame typeracer;
|
||||||
SpeedTyping.RunningContests.TryRemove(serverId, out typeracer);
|
SpeedTyping.RunningContests.TryRemove(serverId, out typeracer);
|
||||||
|
|
||||||
|
@ -3,8 +3,8 @@ using Discord.Modules;
|
|||||||
using NadekoBot.Classes;
|
using NadekoBot.Classes;
|
||||||
using NadekoBot.Classes._DataModels;
|
using NadekoBot.Classes._DataModels;
|
||||||
using NadekoBot.Classes.JSONModels;
|
using NadekoBot.Classes.JSONModels;
|
||||||
using NadekoBot.Classes.Permissions;
|
|
||||||
using NadekoBot.Extensions;
|
using NadekoBot.Extensions;
|
||||||
|
using NadekoBot.Modules.Permissions.Classes;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using NadekoBot.Commands;
|
using NadekoBot.Classes;
|
||||||
using ScaredFingers.UnitsConversion;
|
using ScaredFingers.UnitsConversion;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using NadekoBot.Classes;
|
using NadekoBot.Classes;
|
||||||
using NadekoBot.Commands;
|
using NadekoBot.Classes;
|
||||||
using NadekoBot.Extensions;
|
using NadekoBot.Extensions;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using System;
|
using System;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using NadekoBot.Commands;
|
using NadekoBot.Classes;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace NadekoBot.Modules.Searches.Commands
|
namespace NadekoBot.Modules.Searches.Commands
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using NadekoBot.Classes;
|
using NadekoBot.Classes;
|
||||||
using NadekoBot.Classes.JSONModels;
|
using NadekoBot.Classes.JSONModels;
|
||||||
using NadekoBot.Classes.Permissions;
|
using NadekoBot.Classes;
|
||||||
using NadekoBot.Commands;
|
using NadekoBot.Modules.Permissions.Classes;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
|
@ -4,6 +4,7 @@ using NadekoBot.Classes;
|
|||||||
using NadekoBot.Classes.IMDB;
|
using NadekoBot.Classes.IMDB;
|
||||||
using NadekoBot.Classes.JSONModels;
|
using NadekoBot.Classes.JSONModels;
|
||||||
using NadekoBot.Extensions;
|
using NadekoBot.Extensions;
|
||||||
|
using NadekoBot.Modules.Permissions.Classes;
|
||||||
using NadekoBot.Modules.Searches.Commands;
|
using NadekoBot.Modules.Searches.Commands;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
@ -35,7 +36,7 @@ namespace NadekoBot.Modules.Searches
|
|||||||
manager.CreateCommands("", cgb =>
|
manager.CreateCommands("", cgb =>
|
||||||
{
|
{
|
||||||
|
|
||||||
cgb.AddCheck(Classes.Permissions.PermissionChecker.Instance);
|
cgb.AddCheck(PermissionChecker.Instance);
|
||||||
|
|
||||||
commands.ForEach(cmd => cmd.Init(cgb));
|
commands.ForEach(cmd => cmd.Init(cgb));
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using NadekoBot.Commands;
|
using NadekoBot.Classes;
|
||||||
using NadekoBot.Modules.Translator.Helpers;
|
using NadekoBot.Modules.Translator.Helpers;
|
||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using Discord.Modules;
|
using Discord.Modules;
|
||||||
using NadekoBot.Extensions;
|
using NadekoBot.Extensions;
|
||||||
|
using NadekoBot.Modules.Permissions.Classes;
|
||||||
|
|
||||||
namespace NadekoBot.Modules.Translator
|
namespace NadekoBot.Modules.Translator
|
||||||
{
|
{
|
||||||
@ -17,7 +18,7 @@ namespace NadekoBot.Modules.Translator
|
|||||||
{
|
{
|
||||||
manager.CreateCommands("", cgb =>
|
manager.CreateCommands("", cgb =>
|
||||||
{
|
{
|
||||||
cgb.AddCheck(Classes.Permissions.PermissionChecker.Instance);
|
cgb.AddCheck(PermissionChecker.Instance);
|
||||||
commands.ForEach(cmd => cmd.Init(cgb));
|
commands.ForEach(cmd => cmd.Init(cgb));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using NadekoBot.Commands;
|
using NadekoBot.Classes;
|
||||||
using NadekoBot.Modules.Translator.Helpers;
|
using NadekoBot.Modules.Translator.Helpers;
|
||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using Manatee.Trello;
|
using Manatee.Trello;
|
||||||
using Manatee.Trello.ManateeJson;
|
using Manatee.Trello.ManateeJson;
|
||||||
using NadekoBot.Extensions;
|
using NadekoBot.Extensions;
|
||||||
|
using NadekoBot.Modules.Permissions.Classes;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -65,7 +66,7 @@ namespace NadekoBot.Modules.Trello
|
|||||||
manager.CreateCommands("trello ", cgb =>
|
manager.CreateCommands("trello ", cgb =>
|
||||||
{
|
{
|
||||||
|
|
||||||
cgb.AddCheck(Classes.Permissions.PermissionChecker.Instance);
|
cgb.AddCheck(PermissionChecker.Instance);
|
||||||
|
|
||||||
cgb.CreateCommand("join")
|
cgb.CreateCommand("join")
|
||||||
.Alias("j")
|
.Alias("j")
|
||||||
|
@ -3,7 +3,7 @@ using Discord.Audio;
|
|||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Discord.Modules;
|
using Discord.Modules;
|
||||||
using NadekoBot.Classes.JSONModels;
|
using NadekoBot.Classes.JSONModels;
|
||||||
using NadekoBot.Commands.Help.Commands;
|
using NadekoBot.Classes.Help.Commands;
|
||||||
using NadekoBot.Modules.Administration;
|
using NadekoBot.Modules.Administration;
|
||||||
using NadekoBot.Modules.ClashOfClans;
|
using NadekoBot.Modules.ClashOfClans;
|
||||||
using NadekoBot.Modules.Conversations;
|
using NadekoBot.Modules.Conversations;
|
||||||
@ -14,6 +14,7 @@ using NadekoBot.Modules.Help;
|
|||||||
using NadekoBot.Modules.Music;
|
using NadekoBot.Modules.Music;
|
||||||
using NadekoBot.Modules.NSFW;
|
using NadekoBot.Modules.NSFW;
|
||||||
using NadekoBot.Modules.Permissions;
|
using NadekoBot.Modules.Permissions;
|
||||||
|
using NadekoBot.Modules.Permissions.Classes;
|
||||||
using NadekoBot.Modules.Pokemon;
|
using NadekoBot.Modules.Pokemon;
|
||||||
using NadekoBot.Modules.Searches;
|
using NadekoBot.Modules.Searches;
|
||||||
using NadekoBot.Modules.Translator;
|
using NadekoBot.Modules.Translator;
|
||||||
@ -233,7 +234,7 @@ namespace NadekoBot
|
|||||||
if (string.IsNullOrWhiteSpace(request.Content))
|
if (string.IsNullOrWhiteSpace(request.Content))
|
||||||
e.Cancel = true;
|
e.Cancel = true;
|
||||||
};
|
};
|
||||||
Classes.Permissions.PermissionsHandler.Initialize();
|
PermissionsHandler.Initialize();
|
||||||
NadekoBot.Ready = true;
|
NadekoBot.Ready = true;
|
||||||
});
|
});
|
||||||
Console.WriteLine("Exiting...");
|
Console.WriteLine("Exiting...");
|
||||||
|
Loading…
Reference in New Issue
Block a user