Split administration into administration and utility. Added incidents table (WIP)
This commit is contained in:
parent
0c46911303
commit
29092206e5
@ -32,6 +32,7 @@ namespace NadekoBot.Classes
|
||||
conn.CreateTable<SongInfo>();
|
||||
conn.CreateTable<PlaylistSongInfo>();
|
||||
conn.CreateTable<MusicPlaylist>();
|
||||
conn.CreateTable<Incident>();
|
||||
conn.Execute(Queries.TransactionTriggerQuery);
|
||||
try
|
||||
{
|
||||
@ -205,7 +206,7 @@ public class PlaylistData
|
||||
|
||||
public static class Queries
|
||||
{
|
||||
public static string TransactionTriggerQuery = @"
|
||||
public const string TransactionTriggerQuery = @"
|
||||
CREATE TRIGGER IF NOT EXISTS OnTransactionAdded
|
||||
AFTER INSERT ON CurrencyTransaction
|
||||
BEGIN
|
||||
@ -216,8 +217,8 @@ INSERT OR REPLACE INTO CurrencyState (Id, UserId, Value, DateAdded)
|
||||
NEW.DateAdded);
|
||||
END
|
||||
";
|
||||
public static string DeletePlaylistTriggerQuery = @"
|
||||
CREATE TRIGGER music_playlist
|
||||
public const string DeletePlaylistTriggerQuery = @"
|
||||
CREATE TRIGGER IF NOT EXISTS music_playlist
|
||||
AFTER DELETE ON MusicPlaylist
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
|
@ -1,9 +1,12 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace NadekoBot.Classes {
|
||||
internal static class IncidentsHandler {
|
||||
public static void Add(ulong serverId, string text) {
|
||||
namespace NadekoBot.Classes
|
||||
{
|
||||
internal static class IncidentsHandler
|
||||
{
|
||||
public static void Add(ulong serverId, string text)
|
||||
{
|
||||
Directory.CreateDirectory("data/incidents");
|
||||
File.AppendAllText($"data/incidents/{serverId}.txt", text + "\n--------------------------\n");
|
||||
var def = Console.ForegroundColor;
|
||||
|
@ -24,8 +24,6 @@ namespace NadekoBot.Modules.Administration
|
||||
commands.Add(new VoicePlusTextCommand(this));
|
||||
commands.Add(new CrossServerTextChannel(this));
|
||||
commands.Add(new SelfAssignedRolesCommand(this));
|
||||
commands.Add(new Remind(this));
|
||||
commands.Add(new InfoCommands(this));
|
||||
commands.Add(new CustomReactionsCommands(this));
|
||||
commands.Add(new AutoAssignRole(this));
|
||||
commands.Add(new SelfCommands(this));
|
||||
@ -293,22 +291,6 @@ namespace NadekoBot.Modules.Administration
|
||||
}
|
||||
});
|
||||
|
||||
cgb.CreateCommand(Prefix + "roles")
|
||||
.Description("List all roles on this server or a single user if specified.")
|
||||
.Parameter("user", ParameterType.Unparsed)
|
||||
.Do(async e =>
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(e.GetArg("user")))
|
||||
{
|
||||
var usr = e.Server.FindUsers(e.GetArg("user")).FirstOrDefault();
|
||||
if (usr == null) return;
|
||||
|
||||
await e.Channel.SendMessage($"`List of roles for **{usr.Name}**:` \n• " + string.Join("\n• ", usr.Roles)).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
await e.Channel.SendMessage("`List of roles:` \n• " + string.Join("\n• ", e.Server.Roles)).ConfigureAwait(false);
|
||||
});
|
||||
|
||||
cgb.CreateCommand(Prefix + "ban").Alias(Prefix + "b")
|
||||
.Parameter("user", ParameterType.Required)
|
||||
.Parameter("msg", ParameterType.Unparsed)
|
||||
@ -630,40 +612,6 @@ namespace NadekoBot.Modules.Administration
|
||||
await e.Channel.SendMessage(":ok: **New channel name set.**").ConfigureAwait(false);
|
||||
});
|
||||
|
||||
cgb.CreateCommand(Prefix + "userid").Alias(Prefix + "uid")
|
||||
.Description("Shows user ID.")
|
||||
.Parameter("user", ParameterType.Unparsed)
|
||||
.Do(async e =>
|
||||
{
|
||||
var usr = e.User;
|
||||
if (!string.IsNullOrWhiteSpace(e.GetArg("user"))) usr = e.Channel.FindUsers(e.GetArg("user")).FirstOrDefault();
|
||||
if (usr == null)
|
||||
return;
|
||||
await e.Channel.SendMessage($"Id of the user { usr.Name } is { usr.Id }").ConfigureAwait(false);
|
||||
});
|
||||
|
||||
cgb.CreateCommand(Prefix + "channelid").Alias(Prefix + "cid")
|
||||
.Description("Shows current channel ID.")
|
||||
.Do(async e => await e.Channel.SendMessage("This channel's ID is " + e.Channel.Id).ConfigureAwait(false));
|
||||
|
||||
cgb.CreateCommand(Prefix + "serverid").Alias(Prefix + "sid")
|
||||
.Description("Shows current server ID.")
|
||||
.Do(async e => await e.Channel.SendMessage("This server's ID is " + e.Server.Id).ConfigureAwait(false));
|
||||
|
||||
cgb.CreateCommand(Prefix + "stats")
|
||||
.Description("Shows some basic stats for Nadeko.")
|
||||
.Do(async e =>
|
||||
{
|
||||
await e.Channel.SendMessage(await NadekoStats.Instance.GetStats());
|
||||
});
|
||||
|
||||
cgb.CreateCommand(Prefix + "dysyd")
|
||||
.Description("Shows some basic stats for Nadeko.")
|
||||
.Do(async e =>
|
||||
{
|
||||
await e.Channel.SendMessage((await NadekoStats.Instance.GetStats()).Matrix().TrimTo(1990)).ConfigureAwait(false);
|
||||
});
|
||||
|
||||
cgb.CreateCommand(Prefix + "heap")
|
||||
.Description("Shows allocated memory - **Bot Owner Only!**")
|
||||
.AddCheck(SimpleCheckers.OwnerOnly())
|
||||
@ -797,19 +745,6 @@ namespace NadekoBot.Modules.Administration
|
||||
client.SetGame(e.GetArg("set_game"));
|
||||
});
|
||||
|
||||
cgb.CreateCommand(Prefix + "checkmyperms")
|
||||
.Description("Checks your userspecific permissions on this channel.")
|
||||
.Do(async e =>
|
||||
{
|
||||
var output = "```\n";
|
||||
foreach (var p in e.User.ServerPermissions.GetType().GetProperties().Where(p => !p.GetGetMethod().GetParameters().Any()))
|
||||
{
|
||||
output += p.Name + ": " + p.GetValue(e.User.ServerPermissions, null).ToString() + "\n";
|
||||
}
|
||||
output += "```";
|
||||
await e.User.SendMessage(output).ConfigureAwait(false);
|
||||
});
|
||||
|
||||
cgb.CreateCommand(Prefix + "send")
|
||||
.Description("Send a message to someone on a different server through the bot. **Bot Owner Only!**\n**Usage**: `.send serverid|u:user_id Send this to a user!` or `.send serverid|c:channel_id Send this to a channel!`")
|
||||
.Parameter("ids", ParameterType.Required)
|
||||
@ -889,37 +824,6 @@ namespace NadekoBot.Modules.Administration
|
||||
}).ConfigureAwait(false);
|
||||
});
|
||||
|
||||
cgb.CreateCommand(Prefix + "inrole")
|
||||
.Description("Lists every person from the provided role or roles (separated by a ',') on this server.")
|
||||
.Parameter("roles", ParameterType.Unparsed)
|
||||
.Do(async e =>
|
||||
{
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
if (!e.User.ServerPermissions.MentionEveryone) return;
|
||||
var arg = e.GetArg("roles").Split(',').Select(r => r.Trim());
|
||||
string send = $"`Here is a list of users in a specfic role:`";
|
||||
foreach (var roleStr in arg.Where(str => !string.IsNullOrWhiteSpace(str)))
|
||||
{
|
||||
var role = e.Server.FindRoles(roleStr).FirstOrDefault();
|
||||
if (role == null) continue;
|
||||
send += $"\n`{role.Name}`\n";
|
||||
send += string.Join(", ", role.Members.Select(r => "**" + r.Name + "**#" + r.Discriminator));
|
||||
}
|
||||
|
||||
while (send.Length > 2000)
|
||||
{
|
||||
var curstr = send.Substring(0, 2000);
|
||||
await
|
||||
e.Channel.Send(curstr.Substring(0,
|
||||
curstr.LastIndexOf(", ", StringComparison.Ordinal) + 1)).ConfigureAwait(false);
|
||||
send = curstr.Substring(curstr.LastIndexOf(", ", StringComparison.Ordinal) + 1) +
|
||||
send.Substring(2000);
|
||||
}
|
||||
await e.Channel.Send(send).ConfigureAwait(false);
|
||||
}).ConfigureAwait(false);
|
||||
});
|
||||
|
||||
cgb.CreateCommand(Prefix + "unstuck")
|
||||
.Description("Clears the message queue. **Bot Owner Only!**")
|
||||
.AddCheck(SimpleCheckers.OwnerOnly())
|
||||
@ -982,27 +886,6 @@ namespace NadekoBot.Modules.Administration
|
||||
await e.Channel.SendMessage(":ok:").ConfigureAwait(false);
|
||||
});
|
||||
|
||||
cgb.CreateCommand(Prefix + "whoplays")
|
||||
.Description("Shows a list of users who are playing the specified game.")
|
||||
.Parameter("game", ParameterType.Unparsed)
|
||||
.Do(async e =>
|
||||
{
|
||||
var game = e.GetArg("game")?.Trim().ToUpperInvariant();
|
||||
if (string.IsNullOrWhiteSpace(game))
|
||||
return;
|
||||
var en = e.Server.Users
|
||||
.Where(u => u.CurrentGame?.Name?.ToUpperInvariant() == game)
|
||||
.Select(u => u.Name);
|
||||
|
||||
var arr = en as string[] ?? en.ToArray();
|
||||
|
||||
int i = 0;
|
||||
if (arr.Length == 0)
|
||||
await e.Channel.SendMessage("Nobody. (not 100% sure)").ConfigureAwait(false);
|
||||
else
|
||||
await e.Channel.SendMessage("```xl\n" + string.Join("\n", arr.GroupBy(item => (i++) / 3).Select(ig => string.Join("", ig.Select(el => $"• {el,-35}")))) + "\n```").ConfigureAwait(false);
|
||||
});
|
||||
|
||||
cgb.CreateCommand(Prefix + "leave")
|
||||
.Description("Leaves a server with a supplied ID.\n**Usage**: `.leave 493243292839`")
|
||||
.Parameter("num", ParameterType.Required)
|
||||
|
@ -6,7 +6,7 @@ using System;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace NadekoBot.Modules.Administration.Commands
|
||||
namespace NadekoBot.Modules.Utility.Commands
|
||||
{
|
||||
class InfoCommands : DiscordCommand
|
||||
{
|
@ -9,7 +9,7 @@ using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Timers;
|
||||
|
||||
namespace NadekoBot.Modules.Administration.Commands
|
||||
namespace NadekoBot.Modules.Utility.Commands
|
||||
{
|
||||
class Remind : DiscordCommand
|
||||
{
|
151
NadekoBot/Modules/Utility/UtilityModule.cs
Normal file
151
NadekoBot/Modules/Utility/UtilityModule.cs
Normal file
@ -0,0 +1,151 @@
|
||||
using Discord.Commands;
|
||||
using Discord.Modules;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Modules.Permissions.Classes;
|
||||
using NadekoBot.Modules.Utility.Commands;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NadekoBot.Modules.Utility
|
||||
{
|
||||
internal class UtilityModule : DiscordModule
|
||||
{
|
||||
public UtilityModule()
|
||||
{
|
||||
commands.Add(new Remind(this));
|
||||
commands.Add(new InfoCommands(this));
|
||||
}
|
||||
|
||||
public override string Prefix => NadekoBot.Config.CommandPrefixes.Utility;
|
||||
|
||||
public override void Install(ModuleManager manager)
|
||||
{
|
||||
|
||||
manager.CreateCommands("", cgb =>
|
||||
{
|
||||
cgb.AddCheck(PermissionChecker.Instance);
|
||||
|
||||
var client = manager.Client;
|
||||
|
||||
commands.ForEach(cmd => cmd.Init(cgb));
|
||||
|
||||
cgb.CreateCommand(Prefix + "whoplays")
|
||||
.Description("Shows a list of users who are playing the specified game.")
|
||||
.Parameter("game", ParameterType.Unparsed)
|
||||
.Do(async e =>
|
||||
{
|
||||
var game = e.GetArg("game")?.Trim().ToUpperInvariant();
|
||||
if (string.IsNullOrWhiteSpace(game))
|
||||
return;
|
||||
var en = e.Server.Users
|
||||
.Where(u => u.CurrentGame?.Name?.ToUpperInvariant() == game)
|
||||
.Select(u => u.Name);
|
||||
|
||||
var arr = en as string[] ?? en.ToArray();
|
||||
|
||||
int i = 0;
|
||||
if (arr.Length == 0)
|
||||
await e.Channel.SendMessage("Nobody. (not 100% sure)").ConfigureAwait(false);
|
||||
else
|
||||
await e.Channel.SendMessage("```xl\n" + string.Join("\n", arr.GroupBy(item => (i++) / 3).Select(ig => string.Join("", ig.Select(el => $"• {el,-35}")))) + "\n```").ConfigureAwait(false);
|
||||
});
|
||||
|
||||
cgb.CreateCommand(Prefix + "inrole")
|
||||
.Description("Lists every person from the provided role or roles (separated by a ',') on this server.")
|
||||
.Parameter("roles", ParameterType.Unparsed)
|
||||
.Do(async e =>
|
||||
{
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
if (!e.User.ServerPermissions.MentionEveryone) return;
|
||||
var arg = e.GetArg("roles").Split(',').Select(r => r.Trim());
|
||||
string send = $"`Here is a list of users in a specfic role:`";
|
||||
foreach (var roleStr in arg.Where(str => !string.IsNullOrWhiteSpace(str)))
|
||||
{
|
||||
var role = e.Server.FindRoles(roleStr).FirstOrDefault();
|
||||
if (role == null) continue;
|
||||
send += $"\n`{role.Name}`\n";
|
||||
send += string.Join(", ", role.Members.Select(r => "**" + r.Name + "**#" + r.Discriminator));
|
||||
}
|
||||
|
||||
while (send.Length > 2000)
|
||||
{
|
||||
var curstr = send.Substring(0, 2000);
|
||||
await
|
||||
e.Channel.Send(curstr.Substring(0,
|
||||
curstr.LastIndexOf(", ", StringComparison.Ordinal) + 1)).ConfigureAwait(false);
|
||||
send = curstr.Substring(curstr.LastIndexOf(", ", StringComparison.Ordinal) + 1) +
|
||||
send.Substring(2000);
|
||||
}
|
||||
await e.Channel.Send(send).ConfigureAwait(false);
|
||||
}).ConfigureAwait(false);
|
||||
});
|
||||
|
||||
cgb.CreateCommand(Prefix + "checkmyperms")
|
||||
.Description("Checks your userspecific permissions on this channel.")
|
||||
.Do(async e =>
|
||||
{
|
||||
var output = "```\n";
|
||||
foreach (var p in e.User.ServerPermissions.GetType().GetProperties().Where(p => !p.GetGetMethod().GetParameters().Any()))
|
||||
{
|
||||
output += p.Name + ": " + p.GetValue(e.User.ServerPermissions, null).ToString() + "\n";
|
||||
}
|
||||
output += "```";
|
||||
await e.User.SendMessage(output).ConfigureAwait(false);
|
||||
});
|
||||
|
||||
cgb.CreateCommand(Prefix + "stats")
|
||||
.Description("Shows some basic stats for Nadeko.")
|
||||
.Do(async e =>
|
||||
{
|
||||
await e.Channel.SendMessage(await NadekoStats.Instance.GetStats());
|
||||
});
|
||||
|
||||
cgb.CreateCommand(Prefix + "dysyd")
|
||||
.Description("Shows some basic stats for Nadeko.")
|
||||
.Do(async e =>
|
||||
{
|
||||
await e.Channel.SendMessage((await NadekoStats.Instance.GetStats()).Matrix().TrimTo(1990)).ConfigureAwait(false);
|
||||
});
|
||||
|
||||
cgb.CreateCommand(Prefix + "userid").Alias(Prefix + "uid")
|
||||
.Description("Shows user ID.")
|
||||
.Parameter("user", ParameterType.Unparsed)
|
||||
.Do(async e =>
|
||||
{
|
||||
var usr = e.User;
|
||||
if (!string.IsNullOrWhiteSpace(e.GetArg("user"))) usr = e.Channel.FindUsers(e.GetArg("user")).FirstOrDefault();
|
||||
if (usr == null)
|
||||
return;
|
||||
await e.Channel.SendMessage($"Id of the user { usr.Name } is { usr.Id }").ConfigureAwait(false);
|
||||
});
|
||||
|
||||
cgb.CreateCommand(Prefix + "channelid").Alias(Prefix + "cid")
|
||||
.Description("Shows current channel ID.")
|
||||
.Do(async e => await e.Channel.SendMessage("This channel's ID is " + e.Channel.Id).ConfigureAwait(false));
|
||||
|
||||
cgb.CreateCommand(Prefix + "serverid").Alias(Prefix + "sid")
|
||||
.Description("Shows current server ID.")
|
||||
.Do(async e => await e.Channel.SendMessage("This server's ID is " + e.Server.Id).ConfigureAwait(false));
|
||||
|
||||
cgb.CreateCommand(Prefix + "roles")
|
||||
.Description("List all roles on this server or a single user if specified.")
|
||||
.Parameter("user", ParameterType.Unparsed)
|
||||
.Do(async e =>
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(e.GetArg("user")))
|
||||
{
|
||||
var usr = e.Server.FindUsers(e.GetArg("user")).FirstOrDefault();
|
||||
if (usr == null) return;
|
||||
|
||||
await e.Channel.SendMessage($"`List of roles for **{usr.Name}**:` \n• " + string.Join("\n• ", usr.Roles)).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
await e.Channel.SendMessage("`List of roles:` \n• " + string.Join("\n• ", e.Server.Roles)).ConfigureAwait(false);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ using NadekoBot.Modules.Pokemon;
|
||||
using NadekoBot.Modules.Searches;
|
||||
using NadekoBot.Modules.Translator;
|
||||
using NadekoBot.Modules.Trello;
|
||||
using NadekoBot.Modules.Utility;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -163,6 +164,7 @@ namespace NadekoBot
|
||||
//install modules
|
||||
modules.Add(new HelpModule(), "Help", ModuleFilter.None);
|
||||
modules.Add(new AdministrationModule(), "Administration", ModuleFilter.None);
|
||||
modules.Add(new UtilityModule(), "Utility", ModuleFilter.None);
|
||||
modules.Add(new PermissionModule(), "Permissions", ModuleFilter.None);
|
||||
modules.Add(new Conversations(), "Conversations", ModuleFilter.None);
|
||||
modules.Add(new GamblingModule(), "Gambling", ModuleFilter.None);
|
||||
|
@ -150,6 +150,8 @@
|
||||
<Compile Include="Classes\IncidentsHandler.cs" />
|
||||
<Compile Include="Modules\Searches\Commands\OsuCommands.cs" />
|
||||
<Compile Include="Modules\Searches\Commands\PokemonSearchCommands.cs" />
|
||||
<Compile Include="Modules\Utility\UtilityModule.cs" />
|
||||
<Compile Include="_Models\DataModels\Incident.cs" />
|
||||
<Compile Include="_Models\JSONModels\AnimeResult.cs" />
|
||||
<Compile Include="_Models\JSONModels\Configuration.cs" />
|
||||
<Compile Include="Modules\Searches\Commands\WowJokes.cs" />
|
||||
@ -188,8 +190,8 @@
|
||||
<Compile Include="Modules\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\Utility\Commands\InfoCommands.cs" />
|
||||
<Compile Include="Modules\Utility\Commands\Remind.cs" />
|
||||
<Compile Include="Modules\Administration\Commands\SelfAssignedRolesCommand.cs" />
|
||||
<Compile Include="Modules\ClashOfClans\ClashOfClansModule.cs" />
|
||||
<Compile Include="Modules\Permissions\Commands\FilterWordsCommand.cs" />
|
||||
|
13
NadekoBot/_Models/DataModels/Incident.cs
Normal file
13
NadekoBot/_Models/DataModels/Incident.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
|
||||
namespace NadekoBot.DataModels
|
||||
{
|
||||
class Incident : IDataModel
|
||||
{
|
||||
public long ServerId { get; set; }
|
||||
public long ChannelId { get; set; }
|
||||
public string Text { get; set; }
|
||||
public DateTime When { get; set; }
|
||||
public bool Read { get; set; } = false;
|
||||
}
|
||||
}
|
@ -161,6 +161,7 @@ Nadeko Support Server: <https://discord.gg/0ehQwTK2RBjAxzEY>";
|
||||
public string Permissions { get; set; } = ";";
|
||||
public string Programming { get; set; } = "%";
|
||||
public string Pokemon { get; set; } = ">";
|
||||
public string Utility { get; set; } = ".";
|
||||
}
|
||||
|
||||
public static class ConfigHandler
|
||||
|
@ -87,7 +87,8 @@
|
||||
"Gambling": "$",
|
||||
"Permissions": ";",
|
||||
"Programming": "%",
|
||||
"Pokemon": ">"
|
||||
"Pokemon": ">",
|
||||
"Utility": "."
|
||||
},
|
||||
"ServerBlacklist": [],
|
||||
"ChannelBlacklist": [],
|
||||
|
Loading…
Reference in New Issue
Block a user