Help, Conversations, Permissions refactored

This commit is contained in:
Master Kwoth 2016-04-14 23:39:10 +02:00
parent 3e6b2df73d
commit eb90bb5bd1
12 changed files with 788 additions and 800 deletions

View File

@ -1,56 +0,0 @@
using Discord;
using Discord.Commands;
using NadekoBot.Classes;
using NadekoBot.Modules;
using System;
namespace NadekoBot.Commands
{
class Bomberman : DiscordCommand
{
public Bomberman(DiscordModule module) : base(module)
{
NadekoBot.Client.MessageReceived += async (s, e) =>
{
if (e.Channel.Id != bombGame.ChannelId) return;
var text = e.Message.Text;
await e.Message.Delete();
HandleBombermanCommand(e.User, text);
};
}
private void HandleBombermanCommand(User user, string text)
{
throw new NotImplementedException();
}
//only one bomberman game can run at any one time
public static BombermanGame bombGame = null;
private readonly object locker = new object();
internal override void Init(CommandGroupBuilder cgb)
{
cgb.CreateCommand($"{Module.Prefix}bmb")
.Description("Creates a bomberman game for this channel or join existing one." +
" If you are 4th player - Game will start. After game starts " +
" everything written in the channel will be autodeleted and treated as a bomberman command." +
" only one bomberman game can run at any one time per bot. Game will run at 1FPS." +
" You must have manage messages permissions in order to create the game.")
.Do(e =>
{
lock (locker)
{
if (bombGame == null || bombGame.Ended)
{
if (!e.User.ServerPermissions.ManageMessages ||
!e.Server.GetUser(NadekoBot.Client.CurrentUser.Id).ServerPermissions.ManageMessages)
{
e.Channel.SendMessage("Both you and Nadeko need manage messages permissions to start a new bomberman game.").Wait();
}
}
}
});
}
}
}

View File

@ -1,36 +1,45 @@
using System; using Discord.Commands;
using NadekoBot.Modules;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord.Commands;
using NadekoBot.Modules;
namespace NadekoBot.Commands { namespace NadekoBot.Commands.Conversations.Commands
internal class CopyCommand : DiscordCommand { {
internal class CopyCommand : DiscordCommand
{
private readonly HashSet<ulong> CopiedUsers = new HashSet<ulong>(); private readonly HashSet<ulong> CopiedUsers = new HashSet<ulong>();
public CopyCommand(DiscordModule module) : base(module) { public CopyCommand(DiscordModule module) : base(module)
{
NadekoBot.Client.MessageReceived += Client_MessageReceived; NadekoBot.Client.MessageReceived += Client_MessageReceived;
} }
private async void Client_MessageReceived(object sender, Discord.MessageEventArgs e) { private async void Client_MessageReceived(object sender, Discord.MessageEventArgs e)
{
if (e.User.Id == NadekoBot.Client.CurrentUser.Id) return; if (e.User.Id == NadekoBot.Client.CurrentUser.Id) return;
try { try
{
if (string.IsNullOrWhiteSpace(e.Message.Text)) if (string.IsNullOrWhiteSpace(e.Message.Text))
return; return;
if (CopiedUsers.Contains(e.User.Id)) { if (CopiedUsers.Contains(e.User.Id))
{
await e.Channel.SendMessage(e.Message.Text); await e.Channel.SendMessage(e.Message.Text);
} }
} catch { } }
catch { }
} }
public Func<CommandEventArgs, Task> DoFunc() => async e => { public Func<CommandEventArgs, Task> DoFunc() => async e =>
{
if (CopiedUsers.Contains(e.User.Id)) return; if (CopiedUsers.Contains(e.User.Id)) return;
CopiedUsers.Add(e.User.Id); CopiedUsers.Add(e.User.Id);
await e.Channel.SendMessage(" I'll start copying you now."); await e.Channel.SendMessage(" I'll start copying you now.");
}; };
internal override void Init(CommandGroupBuilder cgb) { internal override void Init(CommandGroupBuilder cgb)
{
cgb.CreateCommand("copyme") cgb.CreateCommand("copyme")
.Alias("cm") .Alias("cm")
.Description("Nadeko starts copying everything you say. Disable with cs") .Description("Nadeko starts copying everything you say. Disable with cs")
@ -42,7 +51,8 @@ namespace NadekoBot.Commands {
.Do(StopCopy()); .Do(StopCopy());
} }
private Func<CommandEventArgs, Task> StopCopy() => async e => { private Func<CommandEventArgs, Task> StopCopy() => async e =>
{
if (!CopiedUsers.Contains(e.User.Id)) return; if (!CopiedUsers.Contains(e.User.Id)) return;
CopiedUsers.Remove(e.User.Id); CopiedUsers.Remove(e.User.Id);

View File

@ -1,13 +1,17 @@
using System; using Discord.Commands;
using System.Threading.Tasks;
using Discord.Commands;
using NadekoBot.Extensions; using NadekoBot.Extensions;
using NadekoBot.Modules; using NadekoBot.Modules;
using System;
using System.Threading.Tasks;
namespace NadekoBot.Commands { namespace NadekoBot.Commands.Conversations.Commands
internal class RequestsCommand : DiscordCommand { {
public void SaveRequest(CommandEventArgs e, string text) { internal class RequestsCommand : DiscordCommand
Classes.DbHandler.Instance.InsertData(new Classes._DataModels.Request { {
public void SaveRequest(CommandEventArgs e, string text)
{
Classes.DbHandler.Instance.InsertData(new Classes._DataModels.Request
{
RequestText = text, RequestText = text,
UserName = e.User.Name, UserName = e.User.Name,
UserId = (long)e.User.Id, UserId = (long)e.User.Id,
@ -17,18 +21,20 @@ namespace NadekoBot.Commands {
}); });
} }
// todo what if it's too long? // todo what if it's too long?
public string GetRequests() { public string GetRequests()
{
var task = Classes.DbHandler.Instance.GetAllRows<Classes._DataModels.Request>(); var task = Classes.DbHandler.Instance.GetAllRows<Classes._DataModels.Request>();
var str = "Here are all current requests for NadekoBot:\n\n"; var str = "Here are all current requests for NadekoBot:\n\n";
foreach (var reqObj in task) { foreach (var reqObj in task)
{
str += $"{reqObj.Id}. by **{reqObj.UserName}** from **{reqObj.ServerName}** at {reqObj.DateAdded.ToLocalTime()}\n" + str += $"{reqObj.Id}. by **{reqObj.UserName}** from **{reqObj.ServerName}** at {reqObj.DateAdded.ToLocalTime()}\n" +
$"**{reqObj.RequestText}**\n----------\n"; $"**{reqObj.RequestText}**\n----------\n";
} }
return str + "\n__Type [@NadekoBot clr] to clear all of my messages.__"; return str + "\n__Type [@NadekoBot clr] to clear all of my messages.__";
} }
public bool DeleteRequest(int requestNumber) => public bool DeleteRequest(int requestNumber) =>
Classes.DbHandler.Instance.Delete<Classes._DataModels.Request>(requestNumber) != null; Classes.DbHandler.Instance.Delete<Classes._DataModels.Request>(requestNumber) != null;
/// <summary> /// <summary>
@ -38,18 +44,23 @@ namespace NadekoBot.Commands {
public Classes._DataModels.Request ResolveRequest(int requestNumber) => public Classes._DataModels.Request ResolveRequest(int requestNumber) =>
Classes.DbHandler.Instance.Delete<Classes._DataModels.Request>(requestNumber); Classes.DbHandler.Instance.Delete<Classes._DataModels.Request>(requestNumber);
internal override void Init(CommandGroupBuilder cgb) { internal override void Init(CommandGroupBuilder cgb)
{
cgb.CreateCommand("req") cgb.CreateCommand("req")
.Alias("request") .Alias("request")
.Description("Requests a feature for nadeko.\n**Usage**: @NadekoBot req new_feature") .Description("Requests a feature for nadeko.\n**Usage**: @NadekoBot req new_feature")
.Parameter("all", ParameterType.Unparsed) .Parameter("all", ParameterType.Unparsed)
.Do(async e => { .Do(async e =>
{
var str = e.Args[0]; var str = e.Args[0];
try { try
{
SaveRequest(e, str); SaveRequest(e, str);
} catch { }
catch
{
await e.Channel.SendMessage("Something went wrong."); await e.Channel.SendMessage("Something went wrong.");
return; return;
} }
@ -58,7 +69,8 @@ namespace NadekoBot.Commands {
cgb.CreateCommand("lr") cgb.CreateCommand("lr")
.Description("PMs the user all current nadeko requests.") .Description("PMs the user all current nadeko requests.")
.Do(async e => { .Do(async e =>
{
var str = await Task.Run(() => GetRequests()); var str = await Task.Run(() => GetRequests());
if (str.Trim().Length > 110) if (str.Trim().Length > 110)
await e.User.Send(str); await e.User.Send(str);
@ -69,40 +81,58 @@ namespace NadekoBot.Commands {
cgb.CreateCommand("dr") cgb.CreateCommand("dr")
.Description("Deletes a request. Only owner is able to do this.") .Description("Deletes a request. Only owner is able to do this.")
.Parameter("reqNumber", ParameterType.Required) .Parameter("reqNumber", ParameterType.Required)
.Do(async e => { .Do(async e =>
if (NadekoBot.IsOwner(e.User.Id)) { {
try { if (NadekoBot.IsOwner(e.User.Id))
if (DeleteRequest(int.Parse(e.Args[0]))) { {
try
{
if (DeleteRequest(int.Parse(e.Args[0])))
{
await e.Channel.SendMessage(e.User.Mention + " Request deleted."); await e.Channel.SendMessage(e.User.Mention + " Request deleted.");
} else { }
else
{
await e.Channel.SendMessage("No request on that number."); await e.Channel.SendMessage("No request on that number.");
} }
} catch { }
catch
{
await e.Channel.SendMessage("Error deleting request, probably NaN error."); await e.Channel.SendMessage("Error deleting request, probably NaN error.");
} }
} else await e.Channel.SendMessage("You don't have permission to do that."); }
else await e.Channel.SendMessage("You don't have permission to do that.");
}); });
cgb.CreateCommand("rr") cgb.CreateCommand("rr")
.Description("Resolves a request. Only owner is able to do this.") .Description("Resolves a request. Only owner is able to do this.")
.Parameter("reqNumber", ParameterType.Required) .Parameter("reqNumber", ParameterType.Required)
.Do(async e => { .Do(async e =>
if (NadekoBot.IsOwner(e.User.Id)) { {
try { if (NadekoBot.IsOwner(e.User.Id))
{
try
{
var sc = ResolveRequest(int.Parse(e.Args[0])); var sc = ResolveRequest(int.Parse(e.Args[0]));
if (sc != null) { if (sc != null)
{
await e.Channel.SendMessage(e.User.Mention + " Request resolved, notice sent."); await e.Channel.SendMessage(e.User.Mention + " Request resolved, notice sent.");
await NadekoBot.Client.GetServer((ulong)sc.ServerId).GetUser((ulong)sc.UserId).Send("**This request of yours has been resolved:**\n" + sc.RequestText); await NadekoBot.Client.GetServer((ulong)sc.ServerId).GetUser((ulong)sc.UserId).Send("**This request of yours has been resolved:**\n" + sc.RequestText);
} else { }
else
{
await e.Channel.SendMessage("No request on that number."); await e.Channel.SendMessage("No request on that number.");
} }
} catch { }
catch
{
await e.Channel.SendMessage("Error resolving request, probably NaN error."); await e.Channel.SendMessage("Error resolving request, probably NaN error.");
} }
} else await e.Channel.SendMessage("You don't have permission to do that."); }
else await e.Channel.SendMessage("You don't have permission to do that.");
}); });
} }
public RequestsCommand(DiscordModule module) : base(module) {} public RequestsCommand(DiscordModule module) : base(module) { }
} }
} }

View File

@ -2,7 +2,7 @@ using Discord;
using Discord.Commands; using Discord.Commands;
using Discord.Modules; using Discord.Modules;
using NadekoBot.Classes; using NadekoBot.Classes;
using NadekoBot.Commands; using NadekoBot.Commands.Conversations.Commands;
using NadekoBot.Extensions; using NadekoBot.Extensions;
using NadekoBot.Properties; using NadekoBot.Properties;
using System; using System;
@ -13,7 +13,7 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace NadekoBot.Modules namespace NadekoBot.Modules.Conversations
{ {
internal class Conversations : DiscordModule internal class Conversations : DiscordModule
{ {

View File

@ -6,7 +6,7 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace NadekoBot.Commands namespace NadekoBot.Commands.Help.Commands
{ {
internal class HelpCommand : DiscordCommand internal class HelpCommand : DiscordCommand
{ {

View File

@ -1,10 +1,10 @@
using Discord.Commands; using Discord.Commands;
using Discord.Modules; using Discord.Modules;
using NadekoBot.Commands; using NadekoBot.Commands.Help.Commands;
using NadekoBot.Extensions; using NadekoBot.Extensions;
using System.Linq; using System.Linq;
namespace NadekoBot.Modules namespace NadekoBot.Modules.Help
{ {
internal class Help : DiscordModule internal class Help : DiscordModule
{ {

View File

@ -2,12 +2,12 @@
using Discord.Commands; using Discord.Commands;
using NadekoBot.Classes; using NadekoBot.Classes;
using NadekoBot.Classes.Permissions; using NadekoBot.Classes.Permissions;
using NadekoBot.Modules; using NadekoBot.Commands;
using System; using System;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using ServerPermissions = NadekoBot.Classes.Permissions.ServerPermissions; using ServerPermissions = NadekoBot.Classes.Permissions.ServerPermissions;
namespace NadekoBot.Commands namespace NadekoBot.Modules.Permissions.Commands
{ {
internal class FilterInvitesCommand : DiscordCommand internal class FilterInvitesCommand : DiscordCommand
{ {
@ -46,7 +46,7 @@ namespace NadekoBot.Commands
if (serverPerms.Permissions.FilterInvites) if (serverPerms.Permissions.FilterInvites)
return true; return true;
Permissions perms; Classes.Permissions.Permissions perms;
return serverPerms.ChannelPermissions.TryGetValue(channel.Id, out perms) && perms.FilterInvites; return serverPerms.ChannelPermissions.TryGetValue(channel.Id, out perms) && perms.FilterInvites;
} }

View File

@ -2,12 +2,12 @@
using Discord.Commands; using Discord.Commands;
using NadekoBot.Classes; using NadekoBot.Classes;
using NadekoBot.Classes.Permissions; using NadekoBot.Classes.Permissions;
using NadekoBot.Modules; using NadekoBot.Commands;
using System; using System;
using System.Linq; using System.Linq;
using ServerPermissions = NadekoBot.Classes.Permissions.ServerPermissions; using ServerPermissions = NadekoBot.Classes.Permissions.ServerPermissions;
namespace NadekoBot.Commands namespace NadekoBot.Modules.Permissions.Commands
{ {
internal class FilterWords : DiscordCommand internal class FilterWords : DiscordCommand
{ {
@ -44,7 +44,7 @@ namespace NadekoBot.Commands
if (serverPerms.Permissions.FilterWords) if (serverPerms.Permissions.FilterWords)
return true; return true;
Permissions perms; Classes.Permissions.Permissions perms;
return serverPerms.ChannelPermissions.TryGetValue(channel.Id, out perms) && perms.FilterWords; return serverPerms.ChannelPermissions.TryGetValue(channel.Id, out perms) && perms.FilterWords;
} }

View File

@ -4,11 +4,15 @@ using Discord.Commands;
using Discord.Modules; using Discord.Modules;
using NadekoBot.Classes.JSONModels; using NadekoBot.Classes.JSONModels;
using NadekoBot.Commands; using NadekoBot.Commands;
using NadekoBot.Commands.Help.Commands;
using NadekoBot.Modules; using NadekoBot.Modules;
using NadekoBot.Modules.Administration; using NadekoBot.Modules.Administration;
using NadekoBot.Modules.Conversations;
using NadekoBot.Modules.Gambling; using NadekoBot.Modules.Gambling;
using NadekoBot.Modules.Games; using NadekoBot.Modules.Games;
using NadekoBot.Modules.Games.Commands; using NadekoBot.Modules.Games.Commands;
using NadekoBot.Modules.Help;
using NadekoBot.Modules.Permissions;
using NadekoBot.Modules.Pokemon; using NadekoBot.Modules.Pokemon;
using NadekoBot.Modules.Searches; using NadekoBot.Modules.Searches;
using NadekoBot.Modules.Translator; using NadekoBot.Modules.Translator;

View File

@ -160,48 +160,48 @@
<Compile Include="Classes\_DataModels\StatsModel.cs" /> <Compile Include="Classes\_DataModels\StatsModel.cs" />
<Compile Include="Classes\_DataModels\TypingArticleModel.cs" /> <Compile Include="Classes\_DataModels\TypingArticleModel.cs" />
<Compile Include="Classes\_DataModels\UserQuoteModel.cs" /> <Compile Include="Classes\_DataModels\UserQuoteModel.cs" />
<Compile Include="Commands\BetrayGame.cs" /> <Compile Include="Modules\Games\Commands\BetrayGame.cs" />
<Compile Include="Commands\DiscordCommand.cs" /> <Compile Include="Classes\DiscordCommand.cs" />
<Compile Include="Commands\PlantPick.cs" /> <Compile Include="Modules\Games\Commands\PlantPick.cs" />
<Compile Include="Modules\Administration\Commands\CrossServerTextChannel.cs" /> <Compile Include="Modules\Administration\Commands\CrossServerTextChannel.cs" />
<Compile Include="Modules\Administration\Commands\InfoCommands.cs" /> <Compile Include="Modules\Administration\Commands\InfoCommands.cs" />
<Compile Include="Modules\Administration\Commands\Remind.cs" /> <Compile Include="Modules\Administration\Commands\Remind.cs" />
<Compile Include="Modules\Administration\Commands\SelfAssignedRolesCommand.cs" /> <Compile Include="Modules\Administration\Commands\SelfAssignedRolesCommand.cs" />
<Compile Include="Modules\ClashOfClans.cs" /> <Compile Include="Modules\ClashOfClans.cs" />
<Compile Include="Commands\FilterWordsCommand.cs" /> <Compile Include="Modules\Permissions\Commands\FilterWordsCommand.cs" />
<Compile Include="Commands\FilterInvitesCommand.cs" /> <Compile Include="Modules\Permissions\Commands\FilterInvitesCommand.cs" />
<Compile Include="Modules\Administration\Commands\LogCommand.cs" /> <Compile Include="Modules\Administration\Commands\LogCommand.cs" />
<Compile Include="Modules\Searches\Commands\LoLCommands.cs" /> <Compile Include="Modules\Searches\Commands\LoLCommands.cs" />
<Compile Include="Modules\Administration\Commands\MessageRepeater.cs" /> <Compile Include="Modules\Administration\Commands\MessageRepeater.cs" />
<Compile Include="Modules\Administration\Commands\PlayingRotate.cs" /> <Compile Include="Modules\Administration\Commands\PlayingRotate.cs" />
<Compile Include="Modules\Searches\Commands\StreamNotifications.cs" /> <Compile Include="Modules\Searches\Commands\StreamNotifications.cs" />
<Compile Include="Commands\TriviaCommand.cs" /> <Compile Include="Modules\Games\Commands\TriviaCommand.cs" />
<Compile Include="Classes\Trivia\TriviaGame.cs" /> <Compile Include="Classes\Trivia\TriviaGame.cs" />
<Compile Include="Classes\Trivia\TriviaQuestion.cs" /> <Compile Include="Classes\Trivia\TriviaQuestion.cs" />
<Compile Include="Classes\Trivia\TriviaQuestionPool.cs" /> <Compile Include="Classes\Trivia\TriviaQuestionPool.cs" />
<Compile Include="Commands\RequestsCommand.cs" /> <Compile Include="Modules\Conversations\Commands\RequestsCommand.cs" />
<Compile Include="Modules\Administration\Commands\ServerGreetCommand.cs" /> <Compile Include="Modules\Administration\Commands\ServerGreetCommand.cs" />
<Compile Include="Commands\SpeedTyping.cs" /> <Compile Include="Modules\Games\Commands\SpeedTyping.cs" />
<Compile Include="Modules\Gambling\Helpers\Cards.cs" /> <Compile Include="Modules\Gambling\Helpers\Cards.cs" />
<Compile Include="Classes\Extensions.cs" /> <Compile Include="Classes\Extensions.cs" />
<Compile Include="Commands\CopyCommand.cs" /> <Compile Include="Modules\Conversations\Commands\CopyCommand.cs" />
<Compile Include="Modules\Gambling\DiceRollCommand.cs" /> <Compile Include="Modules\Gambling\DiceRollCommand.cs" />
<Compile Include="Modules\Gambling\DrawCommand.cs" /> <Compile Include="Modules\Gambling\DrawCommand.cs" />
<Compile Include="Modules\Gambling\FlipCoinCommand.cs" /> <Compile Include="Modules\Gambling\FlipCoinCommand.cs" />
<Compile Include="Commands\HelpCommand.cs" /> <Compile Include="Modules\Help\Commands\HelpCommand.cs" />
<Compile Include="Modules\Administration\Commands\VoiceNotificationCommand.cs" /> <Compile Include="Modules\Administration\Commands\VoiceNotificationCommand.cs" />
<Compile Include="Modules\Administration\Commands\VoicePlusTextCommand.cs" /> <Compile Include="Modules\Administration\Commands\VoicePlusTextCommand.cs" />
<Compile Include="Modules\Administration\AdministrationModule.cs" /> <Compile Include="Modules\Administration\AdministrationModule.cs" />
<Compile Include="Modules\Conversations.cs" /> <Compile Include="Modules\Conversations\Conversations.cs" />
<Compile Include="Modules\DiscordModule.cs" /> <Compile Include="Modules\DiscordModule.cs" />
<Compile Include="Modules\Gambling\GamblingModule.cs" /> <Compile Include="Modules\Gambling\GamblingModule.cs" />
<Compile Include="Modules\Games\Commands\Bomberman.cs" /> <Compile Include="Modules\Games\Commands\Bomberman.cs" />
<Compile Include="Modules\Games\GamesModule.cs" /> <Compile Include="Modules\Games\GamesModule.cs" />
<Compile Include="Modules\Help.cs" /> <Compile Include="Modules\Help\Help.cs" />
<Compile Include="Modules\Music.cs" /> <Compile Include="Modules\Music.cs" />
<Compile Include="Commands\PollCommand.cs" /> <Compile Include="Modules\Games\Commands\PollCommand.cs" />
<Compile Include="Modules\NSFW.cs" /> <Compile Include="Modules\NSFW.cs" />
<Compile Include="Modules\Permissions.cs" /> <Compile Include="Modules\Permissions\PermissionsModule.cs" />
<Compile Include="Modules\Administration\Commands\RatelimitCommand.cs" /> <Compile Include="Modules\Administration\Commands\RatelimitCommand.cs" />
<Compile Include="Modules\Pokemon\PokemonModule.cs" /> <Compile Include="Modules\Pokemon\PokemonModule.cs" />
<Compile Include="Modules\Pokemon\PokeStats.cs" /> <Compile Include="Modules\Pokemon\PokeStats.cs" />