Help, Conversations, Permissions refactored
This commit is contained in:
parent
3e6b2df73d
commit
eb90bb5bd1
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -1,36 +1,45 @@
|
||||
using System;
|
||||
using Discord.Commands;
|
||||
using NadekoBot.Modules;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
using NadekoBot.Modules;
|
||||
|
||||
namespace NadekoBot.Commands {
|
||||
internal class CopyCommand : DiscordCommand {
|
||||
namespace NadekoBot.Commands.Conversations.Commands
|
||||
{
|
||||
internal class CopyCommand : DiscordCommand
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
try {
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(e.Message.Text))
|
||||
return;
|
||||
if (CopiedUsers.Contains(e.User.Id)) {
|
||||
if (CopiedUsers.Contains(e.User.Id))
|
||||
{
|
||||
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;
|
||||
|
||||
CopiedUsers.Add(e.User.Id);
|
||||
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")
|
||||
.Alias("cm")
|
||||
.Description("Nadeko starts copying everything you say. Disable with cs")
|
||||
@ -42,7 +51,8 @@ namespace NadekoBot.Commands {
|
||||
.Do(StopCopy());
|
||||
}
|
||||
|
||||
private Func<CommandEventArgs, Task> StopCopy() => async e => {
|
||||
private Func<CommandEventArgs, Task> StopCopy() => async e =>
|
||||
{
|
||||
if (!CopiedUsers.Contains(e.User.Id)) return;
|
||||
|
||||
CopiedUsers.Remove(e.User.Id);
|
@ -1,13 +1,17 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
using Discord.Commands;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Modules;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NadekoBot.Commands {
|
||||
internal class RequestsCommand : DiscordCommand {
|
||||
public void SaveRequest(CommandEventArgs e, string text) {
|
||||
Classes.DbHandler.Instance.InsertData(new Classes._DataModels.Request {
|
||||
namespace NadekoBot.Commands.Conversations.Commands
|
||||
{
|
||||
internal class RequestsCommand : DiscordCommand
|
||||
{
|
||||
public void SaveRequest(CommandEventArgs e, string text)
|
||||
{
|
||||
Classes.DbHandler.Instance.InsertData(new Classes._DataModels.Request
|
||||
{
|
||||
RequestText = text,
|
||||
UserName = e.User.Name,
|
||||
UserId = (long)e.User.Id,
|
||||
@ -17,11 +21,13 @@ namespace NadekoBot.Commands {
|
||||
});
|
||||
}
|
||||
// todo what if it's too long?
|
||||
public string GetRequests() {
|
||||
public string GetRequests()
|
||||
{
|
||||
var task = Classes.DbHandler.Instance.GetAllRows<Classes._DataModels.Request>();
|
||||
|
||||
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" +
|
||||
$"**{reqObj.RequestText}**\n----------\n";
|
||||
}
|
||||
@ -38,18 +44,23 @@ namespace NadekoBot.Commands {
|
||||
public Classes._DataModels.Request ResolveRequest(int requestNumber) =>
|
||||
Classes.DbHandler.Instance.Delete<Classes._DataModels.Request>(requestNumber);
|
||||
|
||||
internal override void Init(CommandGroupBuilder cgb) {
|
||||
internal override void Init(CommandGroupBuilder cgb)
|
||||
{
|
||||
|
||||
cgb.CreateCommand("req")
|
||||
.Alias("request")
|
||||
.Description("Requests a feature for nadeko.\n**Usage**: @NadekoBot req new_feature")
|
||||
.Parameter("all", ParameterType.Unparsed)
|
||||
.Do(async e => {
|
||||
.Do(async e =>
|
||||
{
|
||||
var str = e.Args[0];
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
SaveRequest(e, str);
|
||||
} catch {
|
||||
}
|
||||
catch
|
||||
{
|
||||
await e.Channel.SendMessage("Something went wrong.");
|
||||
return;
|
||||
}
|
||||
@ -58,7 +69,8 @@ namespace NadekoBot.Commands {
|
||||
|
||||
cgb.CreateCommand("lr")
|
||||
.Description("PMs the user all current nadeko requests.")
|
||||
.Do(async e => {
|
||||
.Do(async e =>
|
||||
{
|
||||
var str = await Task.Run(() => GetRequests());
|
||||
if (str.Trim().Length > 110)
|
||||
await e.User.Send(str);
|
||||
@ -69,40 +81,58 @@ namespace NadekoBot.Commands {
|
||||
cgb.CreateCommand("dr")
|
||||
.Description("Deletes a request. Only owner is able to do this.")
|
||||
.Parameter("reqNumber", ParameterType.Required)
|
||||
.Do(async e => {
|
||||
if (NadekoBot.IsOwner(e.User.Id)) {
|
||||
try {
|
||||
if (DeleteRequest(int.Parse(e.Args[0]))) {
|
||||
.Do(async e =>
|
||||
{
|
||||
if (NadekoBot.IsOwner(e.User.Id))
|
||||
{
|
||||
try
|
||||
{
|
||||
if (DeleteRequest(int.Parse(e.Args[0])))
|
||||
{
|
||||
await e.Channel.SendMessage(e.User.Mention + " Request deleted.");
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
await e.Channel.SendMessage("No request on that number.");
|
||||
}
|
||||
} catch {
|
||||
}
|
||||
catch
|
||||
{
|
||||
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")
|
||||
.Description("Resolves a request. Only owner is able to do this.")
|
||||
.Parameter("reqNumber", ParameterType.Required)
|
||||
.Do(async e => {
|
||||
if (NadekoBot.IsOwner(e.User.Id)) {
|
||||
try {
|
||||
.Do(async e =>
|
||||
{
|
||||
if (NadekoBot.IsOwner(e.User.Id))
|
||||
{
|
||||
try
|
||||
{
|
||||
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 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.");
|
||||
}
|
||||
} catch {
|
||||
}
|
||||
catch
|
||||
{
|
||||
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) { }
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@ using Discord;
|
||||
using Discord.Commands;
|
||||
using Discord.Modules;
|
||||
using NadekoBot.Classes;
|
||||
using NadekoBot.Commands;
|
||||
using NadekoBot.Commands.Conversations.Commands;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Properties;
|
||||
using System;
|
||||
@ -13,7 +13,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NadekoBot.Modules
|
||||
namespace NadekoBot.Modules.Conversations
|
||||
{
|
||||
internal class Conversations : DiscordModule
|
||||
{
|
@ -6,7 +6,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NadekoBot.Commands
|
||||
namespace NadekoBot.Commands.Help.Commands
|
||||
{
|
||||
internal class HelpCommand : DiscordCommand
|
||||
{
|
@ -1,10 +1,10 @@
|
||||
using Discord.Commands;
|
||||
using Discord.Modules;
|
||||
using NadekoBot.Commands;
|
||||
using NadekoBot.Commands.Help.Commands;
|
||||
using NadekoBot.Extensions;
|
||||
using System.Linq;
|
||||
|
||||
namespace NadekoBot.Modules
|
||||
namespace NadekoBot.Modules.Help
|
||||
{
|
||||
internal class Help : DiscordModule
|
||||
{
|
@ -2,12 +2,12 @@
|
||||
using Discord.Commands;
|
||||
using NadekoBot.Classes;
|
||||
using NadekoBot.Classes.Permissions;
|
||||
using NadekoBot.Modules;
|
||||
using NadekoBot.Commands;
|
||||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
using ServerPermissions = NadekoBot.Classes.Permissions.ServerPermissions;
|
||||
|
||||
namespace NadekoBot.Commands
|
||||
namespace NadekoBot.Modules.Permissions.Commands
|
||||
{
|
||||
internal class FilterInvitesCommand : DiscordCommand
|
||||
{
|
||||
@ -46,7 +46,7 @@ namespace NadekoBot.Commands
|
||||
if (serverPerms.Permissions.FilterInvites)
|
||||
return true;
|
||||
|
||||
Permissions perms;
|
||||
Classes.Permissions.Permissions perms;
|
||||
return serverPerms.ChannelPermissions.TryGetValue(channel.Id, out perms) && perms.FilterInvites;
|
||||
}
|
||||
|
@ -2,12 +2,12 @@
|
||||
using Discord.Commands;
|
||||
using NadekoBot.Classes;
|
||||
using NadekoBot.Classes.Permissions;
|
||||
using NadekoBot.Modules;
|
||||
using NadekoBot.Commands;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using ServerPermissions = NadekoBot.Classes.Permissions.ServerPermissions;
|
||||
|
||||
namespace NadekoBot.Commands
|
||||
namespace NadekoBot.Modules.Permissions.Commands
|
||||
{
|
||||
internal class FilterWords : DiscordCommand
|
||||
{
|
||||
@ -44,7 +44,7 @@ namespace NadekoBot.Commands
|
||||
if (serverPerms.Permissions.FilterWords)
|
||||
return true;
|
||||
|
||||
Permissions perms;
|
||||
Classes.Permissions.Permissions perms;
|
||||
return serverPerms.ChannelPermissions.TryGetValue(channel.Id, out perms) && perms.FilterWords;
|
||||
}
|
||||
|
@ -2,15 +2,15 @@
|
||||
using Discord.Modules;
|
||||
using NadekoBot.Classes.JSONModels;
|
||||
using NadekoBot.Classes.Permissions;
|
||||
using NadekoBot.Commands;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Modules.Games.Commands;
|
||||
using NadekoBot.Modules.Permissions.Commands;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using PermsHandler = NadekoBot.Classes.Permissions.PermissionsHandler;
|
||||
|
||||
namespace NadekoBot.Modules
|
||||
namespace NadekoBot.Modules.Permissions
|
||||
{
|
||||
internal class PermissionModule : DiscordModule
|
||||
{
|
@ -4,11 +4,15 @@ using Discord.Commands;
|
||||
using Discord.Modules;
|
||||
using NadekoBot.Classes.JSONModels;
|
||||
using NadekoBot.Commands;
|
||||
using NadekoBot.Commands.Help.Commands;
|
||||
using NadekoBot.Modules;
|
||||
using NadekoBot.Modules.Administration;
|
||||
using NadekoBot.Modules.Conversations;
|
||||
using NadekoBot.Modules.Gambling;
|
||||
using NadekoBot.Modules.Games;
|
||||
using NadekoBot.Modules.Games.Commands;
|
||||
using NadekoBot.Modules.Help;
|
||||
using NadekoBot.Modules.Permissions;
|
||||
using NadekoBot.Modules.Pokemon;
|
||||
using NadekoBot.Modules.Searches;
|
||||
using NadekoBot.Modules.Translator;
|
||||
|
@ -160,48 +160,48 @@
|
||||
<Compile Include="Classes\_DataModels\StatsModel.cs" />
|
||||
<Compile Include="Classes\_DataModels\TypingArticleModel.cs" />
|
||||
<Compile Include="Classes\_DataModels\UserQuoteModel.cs" />
|
||||
<Compile Include="Commands\BetrayGame.cs" />
|
||||
<Compile Include="Commands\DiscordCommand.cs" />
|
||||
<Compile Include="Commands\PlantPick.cs" />
|
||||
<Compile Include="Modules\Games\Commands\BetrayGame.cs" />
|
||||
<Compile Include="Classes\DiscordCommand.cs" />
|
||||
<Compile Include="Modules\Games\Commands\PlantPick.cs" />
|
||||
<Compile Include="Modules\Administration\Commands\CrossServerTextChannel.cs" />
|
||||
<Compile Include="Modules\Administration\Commands\InfoCommands.cs" />
|
||||
<Compile Include="Modules\Administration\Commands\Remind.cs" />
|
||||
<Compile Include="Modules\Administration\Commands\SelfAssignedRolesCommand.cs" />
|
||||
<Compile Include="Modules\ClashOfClans.cs" />
|
||||
<Compile Include="Commands\FilterWordsCommand.cs" />
|
||||
<Compile Include="Commands\FilterInvitesCommand.cs" />
|
||||
<Compile Include="Modules\Permissions\Commands\FilterWordsCommand.cs" />
|
||||
<Compile Include="Modules\Permissions\Commands\FilterInvitesCommand.cs" />
|
||||
<Compile Include="Modules\Administration\Commands\LogCommand.cs" />
|
||||
<Compile Include="Modules\Searches\Commands\LoLCommands.cs" />
|
||||
<Compile Include="Modules\Administration\Commands\MessageRepeater.cs" />
|
||||
<Compile Include="Modules\Administration\Commands\PlayingRotate.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\TriviaQuestion.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="Commands\SpeedTyping.cs" />
|
||||
<Compile Include="Modules\Games\Commands\SpeedTyping.cs" />
|
||||
<Compile Include="Modules\Gambling\Helpers\Cards.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\DrawCommand.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\VoicePlusTextCommand.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\Gambling\GamblingModule.cs" />
|
||||
<Compile Include="Modules\Games\Commands\Bomberman.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="Commands\PollCommand.cs" />
|
||||
<Compile Include="Modules\Games\Commands\PollCommand.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\Pokemon\PokemonModule.cs" />
|
||||
<Compile Include="Modules\Pokemon\PokeStats.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user