very minor things, added disguise, code reorganizaiton
This commit is contained in:
parent
1bc681e1aa
commit
aa62ac21a2
@ -12,6 +12,8 @@ using NadekoBot.Classes;
|
|||||||
namespace NadekoBot.Extensions {
|
namespace NadekoBot.Extensions {
|
||||||
public static class Extensions
|
public static class Extensions
|
||||||
{
|
{
|
||||||
|
private static Random rng = new Random();
|
||||||
|
|
||||||
public static string Scramble(this string word) {
|
public static string Scramble(this string word) {
|
||||||
|
|
||||||
var letters = word.ToArray();
|
var letters = word.ToArray();
|
||||||
@ -32,7 +34,7 @@ namespace NadekoBot.Extensions {
|
|||||||
}
|
}
|
||||||
return "`"+string.Join(" ", letters)+"`";
|
return "`"+string.Join(" ", letters)+"`";
|
||||||
}
|
}
|
||||||
public static string TrimTo(this string str, int num) {
|
public static string TrimTo(this string str, int num, bool hideDots = false) {
|
||||||
if (num < 0)
|
if (num < 0)
|
||||||
throw new ArgumentOutOfRangeException(nameof(num), "TrimTo argument cannot be less than 0");
|
throw new ArgumentOutOfRangeException(nameof(num), "TrimTo argument cannot be less than 0");
|
||||||
if (num == 0)
|
if (num == 0)
|
||||||
@ -41,7 +43,7 @@ namespace NadekoBot.Extensions {
|
|||||||
return string.Join("", str.Select(c => '.'));
|
return string.Join("", str.Select(c => '.'));
|
||||||
if (str.Length < num)
|
if (str.Length < num)
|
||||||
return str;
|
return str;
|
||||||
return string.Join("", str.Take(num - 3)) + "...";
|
return string.Join("", str.Take(num - 3)) + (hideDots ? "" : "...");
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Removes trailing S or ES (if specified) on the given string if the num is 1
|
/// Removes trailing S or ES (if specified) on the given string if the num is 1
|
||||||
@ -162,6 +164,11 @@ namespace NadekoBot.Extensions {
|
|||||||
/// <param name="action"></param>
|
/// <param name="action"></param>
|
||||||
public static string GetRuntime(this DiscordClient c) => ".Net Framework 4.5.2";
|
public static string GetRuntime(this DiscordClient c) => ".Net Framework 4.5.2";
|
||||||
|
|
||||||
|
public static string Matrix(this string s)
|
||||||
|
=>
|
||||||
|
string.Join("", s.Select(c => c.ToString() + " ̵̢̬̜͉̞̭̖̰͋̉̎ͬ̔̇̌̀".TrimTo(rng.Next(0, 12), true)));
|
||||||
|
//.Replace("`", "");
|
||||||
|
|
||||||
public static void ForEach<T>(this IEnumerable<T> source, Action<T> action) {
|
public static void ForEach<T>(this IEnumerable<T> source, Action<T> action) {
|
||||||
foreach (var element in source) {
|
foreach (var element in source) {
|
||||||
action(element);
|
action(element);
|
||||||
|
@ -16,6 +16,13 @@ namespace NadekoBot.Classes.JSONModels {
|
|||||||
143515953525817344
|
143515953525817344
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public string[] DisguiseResponses { get; } = {
|
||||||
|
"https://cdn.discordapp.com/attachments/140007341880901632/156721710458994690/Cc5mixjUYAADgBs.jpg",
|
||||||
|
"https://cdn.discordapp.com/attachments/140007341880901632/156721715831898113/hqdefault.jpg",
|
||||||
|
"https://cdn.discordapp.com/attachments/140007341880901632/156721724430352385/okawari_01_haruka_weird_mask.jpg",
|
||||||
|
"https://cdn.discordapp.com/attachments/140007341880901632/156721728763068417/mustache-best-girl.png"
|
||||||
|
};
|
||||||
|
|
||||||
public string[] CryResponses { get; } = {
|
public string[] CryResponses { get; } = {
|
||||||
"http://i.imgur.com/Xg3i1Qy.gif",
|
"http://i.imgur.com/Xg3i1Qy.gif",
|
||||||
"http://i.imgur.com/3K8DRrU.gif",
|
"http://i.imgur.com/3K8DRrU.gif",
|
||||||
|
@ -8,11 +8,10 @@ namespace NadekoBot.Classes.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>(6, 0),
|
new Tuple<int, int>(9, 0),
|
||||||
new Tuple<int, int>(7, 1),
|
new Tuple<int, int>(14, 1),
|
||||||
new Tuple<int, int>(12, 2),
|
new Tuple<int, int>(19, 2),
|
||||||
new Tuple<int, int>(17, 3),
|
new Tuple<int, int>(22, 3),
|
||||||
new Tuple<int, int>(22, 4),
|
|
||||||
};
|
};
|
||||||
public static int maxStringLength = 22;
|
public static int maxStringLength = 22;
|
||||||
|
|
||||||
|
@ -10,29 +10,10 @@ using NadekoBot.Classes.Permissions;
|
|||||||
namespace NadekoBot.Commands {
|
namespace NadekoBot.Commands {
|
||||||
internal class LogCommand : IDiscordCommand {
|
internal class LogCommand : IDiscordCommand {
|
||||||
|
|
||||||
private class Repeater {
|
|
||||||
public readonly Timer MessageTimer = new Timer();
|
|
||||||
public Channel ReChannel { get; set; }
|
|
||||||
public string ReMessage { get; set; }
|
|
||||||
|
|
||||||
public Repeater() {
|
|
||||||
MessageTimer.Elapsed += async (s, e) => {
|
|
||||||
try {
|
|
||||||
var ch = ReChannel;
|
|
||||||
var msg = ReMessage;
|
|
||||||
if (ch != null && !string.IsNullOrWhiteSpace(msg))
|
|
||||||
await ch.SendMessage(msg);
|
|
||||||
} catch { }
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private readonly ConcurrentDictionary<Server, Channel> logs = new ConcurrentDictionary<Server, Channel>();
|
private readonly ConcurrentDictionary<Server, Channel> logs = new ConcurrentDictionary<Server, Channel>();
|
||||||
private readonly ConcurrentDictionary<Server, Channel> loggingPresences = new ConcurrentDictionary<Server, Channel>();
|
private readonly ConcurrentDictionary<Server, Channel> loggingPresences = new ConcurrentDictionary<Server, Channel>();
|
||||||
private readonly ConcurrentDictionary<Channel, Channel> voiceChannelLog = new ConcurrentDictionary<Channel, Channel>();
|
private readonly ConcurrentDictionary<Channel, Channel> voiceChannelLog = new ConcurrentDictionary<Channel, Channel>();
|
||||||
|
|
||||||
private readonly ConcurrentDictionary<Server, Repeater> repeaters = new ConcurrentDictionary<Server, Repeater>();
|
|
||||||
|
|
||||||
public LogCommand() {
|
public LogCommand() {
|
||||||
NadekoBot.Client.MessageReceived += MsgRecivd;
|
NadekoBot.Client.MessageReceived += MsgRecivd;
|
||||||
NadekoBot.Client.MessageDeleted += MsgDltd;
|
NadekoBot.Client.MessageDeleted += MsgDltd;
|
||||||
@ -139,44 +120,6 @@ namespace NadekoBot.Commands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void Init(CommandGroupBuilder cgb) {
|
public void Init(CommandGroupBuilder cgb) {
|
||||||
cgb.CreateCommand(".repeat")
|
|
||||||
.Description("Repeat a message every X minutes. If no parameters are specified, repeat is disabled. Requires manage messages.")
|
|
||||||
.Parameter("minutes", ParameterType.Optional)
|
|
||||||
.Parameter("msg", ParameterType.Unparsed)
|
|
||||||
.AddCheck(SimpleCheckers.ManageMessages())
|
|
||||||
.Do(async e => {
|
|
||||||
var minutesStr = e.GetArg("minutes");
|
|
||||||
var msg = e.GetArg("msg");
|
|
||||||
|
|
||||||
// if both null, disable
|
|
||||||
if (string.IsNullOrWhiteSpace(msg) && string.IsNullOrWhiteSpace(minutesStr)) {
|
|
||||||
await e.Channel.SendMessage("Repeating disabled");
|
|
||||||
Repeater rep;
|
|
||||||
if (repeaters.TryGetValue(e.Server, out rep))
|
|
||||||
rep.MessageTimer.Stop();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int minutes;
|
|
||||||
if (!int.TryParse(minutesStr, out minutes) || minutes < 1 || minutes > 720) {
|
|
||||||
await e.Channel.SendMessage("Invalid value");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var repeater = repeaters.GetOrAdd(e.Server, s => new Repeater());
|
|
||||||
|
|
||||||
repeater.ReChannel = e.Channel;
|
|
||||||
repeater.MessageTimer.Interval = minutes * 60 * 1000;
|
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(msg))
|
|
||||||
repeater.ReMessage = msg;
|
|
||||||
|
|
||||||
repeater.MessageTimer.Stop();
|
|
||||||
repeater.MessageTimer.Start();
|
|
||||||
|
|
||||||
await e.Channel.SendMessage(String.Format("👌 Repeating `{0}` every " +
|
|
||||||
"**{1}** minutes on {2} channel.",
|
|
||||||
repeater.ReMessage, minutes, repeater.ReChannel));
|
|
||||||
});
|
|
||||||
|
|
||||||
cgb.CreateCommand(".logserver")
|
cgb.CreateCommand(".logserver")
|
||||||
.Description("Toggles logging in this channel. Logs every message sent/deleted/edited on the server. BOT OWNER ONLY. SERVER OWNER ONLY.")
|
.Description("Toggles logging in this channel. Logs every message sent/deleted/edited on the server. BOT OWNER ONLY. SERVER OWNER ONLY.")
|
||||||
|
89
NadekoBot/Commands/MessageRepeater.cs
Normal file
89
NadekoBot/Commands/MessageRepeater.cs
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
using System;
|
||||||
|
using System.Timers;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
using Discord;
|
||||||
|
using NadekoBot.Classes.Permissions;
|
||||||
|
using Discord.Commands;
|
||||||
|
|
||||||
|
namespace NadekoBot.Commands {
|
||||||
|
class MessageRepeater : IDiscordCommand {
|
||||||
|
private readonly ConcurrentDictionary<Server, Repeater> repeaters = new ConcurrentDictionary<Server, Repeater>();
|
||||||
|
private class Repeater {
|
||||||
|
[Newtonsoft.Json.JsonIgnore]
|
||||||
|
public readonly Timer MessageTimer;
|
||||||
|
[Newtonsoft.Json.JsonIgnore]
|
||||||
|
public Channel RepeatingChannel { get; }
|
||||||
|
|
||||||
|
public ulong RepeatingServerId { get; set; }
|
||||||
|
public ulong RepeatingChannelId { get; set; }
|
||||||
|
public string RepeatingMessage { get; set; }
|
||||||
|
public int Interval { get; set; }
|
||||||
|
|
||||||
|
private Repeater(int interval) {
|
||||||
|
this.Interval = interval;
|
||||||
|
MessageTimer = new Timer {Interval = Interval};
|
||||||
|
MessageTimer.Elapsed += async (s, e) => {
|
||||||
|
var ch = RepeatingChannel;
|
||||||
|
var msg = RepeatingMessage;
|
||||||
|
if (ch != null && !string.IsNullOrWhiteSpace(msg)) {
|
||||||
|
try {
|
||||||
|
await ch.SendMessage(msg);
|
||||||
|
} catch { }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private Repeater(int interval, ulong channelId, ulong serverId) : this(interval) {
|
||||||
|
this.RepeatingChannelId = channelId;
|
||||||
|
this.RepeatingServerId = serverId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Repeater(int interval, ulong channelId, ulong serverId, Channel channel)
|
||||||
|
: this(interval,channelId,serverId) {
|
||||||
|
this.RepeatingChannel = channel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void Init(CommandGroupBuilder cgb) {
|
||||||
|
|
||||||
|
cgb.CreateCommand(".repeat")
|
||||||
|
.Description("Repeat a message every X minutes. If no parameters are specified, " +
|
||||||
|
"repeat is disabled. Requires manage messages.")
|
||||||
|
.Parameter("minutes", ParameterType.Optional)
|
||||||
|
.Parameter("msg", ParameterType.Unparsed)
|
||||||
|
.AddCheck(SimpleCheckers.ManageMessages())
|
||||||
|
.Do(async e => {
|
||||||
|
var minutesStr = e.GetArg("minutes");
|
||||||
|
var msg = e.GetArg("msg");
|
||||||
|
|
||||||
|
// if both null, disable
|
||||||
|
if (string.IsNullOrWhiteSpace(msg) && string.IsNullOrWhiteSpace(minutesStr)) {
|
||||||
|
await e.Channel.SendMessage("Repeating disabled");
|
||||||
|
Repeater rep;
|
||||||
|
if (repeaters.TryGetValue(e.Server, out rep))
|
||||||
|
rep.MessageTimer.Stop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int minutes;
|
||||||
|
if (!int.TryParse(minutesStr, out minutes) || minutes < 1 || minutes > 720) {
|
||||||
|
await e.Channel.SendMessage("Invalid value");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var repeater = repeaters.GetOrAdd(
|
||||||
|
e.Server,
|
||||||
|
s => new Repeater(minutes * 60 * 1000, e.Channel.Id, e.Server.Id, e.Channel)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(msg))
|
||||||
|
repeater.RepeatingMessage = msg;
|
||||||
|
|
||||||
|
repeater.MessageTimer.Stop();
|
||||||
|
repeater.MessageTimer.Start();
|
||||||
|
|
||||||
|
await e.Channel.SendMessage(String.Format("👌 Repeating `{0}` every " +
|
||||||
|
"**{1}** minutes on {2} channel.",
|
||||||
|
repeater.RepeatingMessage, minutes, repeater.RepeatingChannel));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -17,8 +17,9 @@ namespace NadekoBot.Modules {
|
|||||||
public Administration() {
|
public Administration() {
|
||||||
commands.Add(new ServerGreetCommand());
|
commands.Add(new ServerGreetCommand());
|
||||||
commands.Add(new LogCommand());
|
commands.Add(new LogCommand());
|
||||||
|
commands.Add(new MessageRepeater());
|
||||||
commands.Add(new PlayingRotate());
|
commands.Add(new PlayingRotate());
|
||||||
commands.Add(new Commands.RatelimitCommand());
|
commands.Add(new RatelimitCommand());
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string Prefix { get; } = ".";
|
public override string Prefix { get; } = ".";
|
||||||
@ -392,6 +393,13 @@ namespace NadekoBot.Modules {
|
|||||||
.Do(async e => {
|
.Do(async e => {
|
||||||
await e.Channel.SendMessage(await NadekoStats.Instance.GetStats());
|
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));
|
||||||
|
});
|
||||||
|
|
||||||
cgb.CreateCommand(Prefix + "heap")
|
cgb.CreateCommand(Prefix + "heap")
|
||||||
.Description("Shows allocated memory - OWNER ONLY")
|
.Description("Shows allocated memory - OWNER ONLY")
|
||||||
.AddCheck(SimpleCheckers.OwnerOnly())
|
.AddCheck(SimpleCheckers.OwnerOnly())
|
||||||
|
@ -190,6 +190,18 @@ namespace NadekoBot.Modules {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
cgb.CreateCommand("disguise")
|
||||||
|
.Description("Tell Nadeko to disguise herself.")
|
||||||
|
.Do(async e => {
|
||||||
|
try {
|
||||||
|
await
|
||||||
|
e.Channel.SendMessage(
|
||||||
|
$"{NadekoBot.Config.DisguiseResponses[rng.Next(0, NadekoBot.Config.DisguiseResponses.Length)]}");
|
||||||
|
} catch {
|
||||||
|
await e.Channel.SendMessage("Error while handling DisguiseResponses check your data/config.json");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
cgb.CreateCommand("are you real")
|
cgb.CreateCommand("are you real")
|
||||||
.Description("Useless.")
|
.Description("Useless.")
|
||||||
.Do(async e => {
|
.Do(async e => {
|
||||||
|
@ -121,7 +121,7 @@ namespace NadekoBot {
|
|||||||
modules.Add(new Conversations(), "Conversations", ModuleFilter.None);
|
modules.Add(new Conversations(), "Conversations", ModuleFilter.None);
|
||||||
modules.Add(new Gambling(), "Gambling", ModuleFilter.None);
|
modules.Add(new Gambling(), "Gambling", ModuleFilter.None);
|
||||||
modules.Add(new Games(), "Games", ModuleFilter.None);
|
modules.Add(new Games(), "Games", ModuleFilter.None);
|
||||||
modules.Add(new Music(), "Music", ModuleFilter.None);
|
//modules.Add(new Music(), "Music", ModuleFilter.None);
|
||||||
modules.Add(new Searches(), "Searches", ModuleFilter.None);
|
modules.Add(new Searches(), "Searches", ModuleFilter.None);
|
||||||
modules.Add(new NSFW(), "NSFW", ModuleFilter.None);
|
modules.Add(new NSFW(), "NSFW", ModuleFilter.None);
|
||||||
if (!string.IsNullOrWhiteSpace(Creds.TrelloAppKey))
|
if (!string.IsNullOrWhiteSpace(Creds.TrelloAppKey))
|
||||||
|
@ -144,6 +144,7 @@
|
|||||||
<Compile Include="Commands\ClashOfClans.cs" />
|
<Compile Include="Commands\ClashOfClans.cs" />
|
||||||
<Compile Include="Commands\LogCommand.cs" />
|
<Compile Include="Commands\LogCommand.cs" />
|
||||||
<Compile Include="Commands\LoLCommands.cs" />
|
<Compile Include="Commands\LoLCommands.cs" />
|
||||||
|
<Compile Include="Commands\MessageRepeater.cs" />
|
||||||
<Compile Include="Commands\PlayingRotate.cs" />
|
<Compile Include="Commands\PlayingRotate.cs" />
|
||||||
<Compile Include="Commands\TriviaCommand.cs" />
|
<Compile Include="Commands\TriviaCommand.cs" />
|
||||||
<Compile Include="Classes\Trivia\TriviaGame.cs" />
|
<Compile Include="Classes\Trivia\TriviaGame.cs" />
|
||||||
|
@ -11,6 +11,12 @@
|
|||||||
119174277298782216,
|
119174277298782216,
|
||||||
143515953525817344
|
143515953525817344
|
||||||
],
|
],
|
||||||
|
"DisguiseResponses": [
|
||||||
|
"https://cdn.discordapp.com/attachments/140007341880901632/156721710458994690/Cc5mixjUYAADgBs.jpg",
|
||||||
|
"https://cdn.discordapp.com/attachments/140007341880901632/156721715831898113/hqdefault.jpg",
|
||||||
|
"https://cdn.discordapp.com/attachments/140007341880901632/156721724430352385/okawari_01_haruka_weird_mask.jpg",
|
||||||
|
"https://cdn.discordapp.com/attachments/140007341880901632/156721728763068417/mustache-best-girl.png"
|
||||||
|
],
|
||||||
"CryResponses": [
|
"CryResponses": [
|
||||||
"http://i.imgur.com/Xg3i1Qy.gif",
|
"http://i.imgur.com/Xg3i1Qy.gif",
|
||||||
"http://i.imgur.com/3K8DRrU.gif",
|
"http://i.imgur.com/3K8DRrU.gif",
|
||||||
|
Loading…
Reference in New Issue
Block a user