Merge remote-tracking branch 'refs/remotes/origin/master' into dev
This commit is contained in:
commit
749da23266
@ -39,7 +39,8 @@ namespace NadekoBot.Modules.Conversations.Commands
|
|||||||
file = RipName(text, string.IsNullOrWhiteSpace(e.GetArg("year"))
|
file = RipName(text, string.IsNullOrWhiteSpace(e.GetArg("year"))
|
||||||
? null
|
? null
|
||||||
: e.GetArg("year"));
|
: e.GetArg("year"));
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
var avatar = await GetAvatar(usr.AvatarUrl);
|
var avatar = await GetAvatar(usr.AvatarUrl);
|
||||||
text = usr.Name;
|
text = usr.Name;
|
||||||
@ -63,16 +64,13 @@ namespace NadekoBot.Modules.Conversations.Commands
|
|||||||
public Stream RipUser(string name, Image avatar, string year = null)
|
public Stream RipUser(string name, Image avatar, string year = null)
|
||||||
{
|
{
|
||||||
var bm = Resources.rip;
|
var bm = Resources.rip;
|
||||||
var offset = name.Length * 2;
|
int width = 300;
|
||||||
var fontSize = 20;
|
var fontSize = width / name.Length -2;
|
||||||
if (name.Length > 10)
|
if (fontSize > 20) fontSize = 20;
|
||||||
{
|
|
||||||
fontSize -= (name.Length - 10) / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO use measure string
|
|
||||||
var g = Graphics.FromImage(bm);
|
var g = Graphics.FromImage(bm);
|
||||||
g.DrawString(name, new Font("Comic Sans MS", fontSize, FontStyle.Bold), Brushes.Black, 100 - offset, 220);
|
Font nameFont = new Font("Comic Sans MS", fontSize, FontStyle.Bold, GraphicsUnit.Pixel);
|
||||||
|
SizeF nameSize = g.MeasureString(name, nameFont);
|
||||||
|
g.DrawString(name, new Font("Comic Sans MS", fontSize, FontStyle.Bold), Brushes.Black, (bm.Width /2 - 8) - (nameSize.Width /2), 243 - nameSize.Height);
|
||||||
g.DrawString((year ?? "?") + " - " + DateTime.Now.Year, new Font("Consolas", 12, FontStyle.Bold), Brushes.Black, 80, 240);
|
g.DrawString((year ?? "?") + " - " + DateTime.Now.Year, new Font("Consolas", 12, FontStyle.Bold), Brushes.Black, 80, 240);
|
||||||
|
|
||||||
g.DrawImage(avatar, 80, 135);
|
g.DrawImage(avatar, 80, 135);
|
||||||
@ -86,19 +84,14 @@ namespace NadekoBot.Modules.Conversations.Commands
|
|||||||
public Stream RipName(string name, string year = null)
|
public Stream RipName(string name, string year = null)
|
||||||
{
|
{
|
||||||
var bm = Resources.rip;
|
var bm = Resources.rip;
|
||||||
|
int width = 190;
|
||||||
var offset = name.Length * 5;
|
var offset = name.Length * 5;
|
||||||
|
var fontSize = width / name.Length;
|
||||||
var fontSize = 20;
|
if (fontSize > 20) fontSize = 20;
|
||||||
|
|
||||||
if (name.Length > 10)
|
|
||||||
{
|
|
||||||
fontSize -= (name.Length - 10) / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO use measure string
|
|
||||||
var g = Graphics.FromImage(bm);
|
var g = Graphics.FromImage(bm);
|
||||||
g.DrawString(name, new Font("Comic Sans MS", fontSize, FontStyle.Bold), Brushes.Black, 100 - offset, 200);
|
Font nameFont = new Font("Comic Sans MS", fontSize, FontStyle.Bold, GraphicsUnit.Pixel);
|
||||||
|
SizeF nameSize = g.MeasureString(name, nameFont);
|
||||||
|
g.DrawString(name, nameFont, Brushes.Black, (bm.Width / 2) - (nameSize.Width / 2), 200);
|
||||||
g.DrawString((year ?? "?") + " - " + DateTime.Now.Year, new Font("Consolas", 12, FontStyle.Bold), Brushes.Black, 80, 235);
|
g.DrawString((year ?? "?") + " - " + DateTime.Now.Year, new Font("Consolas", 12, FontStyle.Bold), Brushes.Black, 80, 235);
|
||||||
g.Flush();
|
g.Flush();
|
||||||
g.Dispose();
|
g.Dispose();
|
||||||
|
@ -5,34 +5,42 @@ using NadekoBot.Modules.Permissions.Classes;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace NadekoBot.Modules.CustomReactions
|
namespace NadekoBot.Modules.CustomReactions
|
||||||
{
|
{
|
||||||
class CustomReactionsModule : DiscordModule
|
internal class CustomReactionsModule : DiscordModule
|
||||||
{
|
{
|
||||||
public override string Prefix { get; } = "";
|
public override string Prefix { get; } = "";
|
||||||
|
|
||||||
Random rng = new Random();
|
private Random rng = new Random();
|
||||||
|
|
||||||
private Dictionary<string, Func<CommandEventArgs, string>> commandFuncs;
|
private Dictionary<Regex, Func<CommandEventArgs, Match, string>> commandFuncs;
|
||||||
|
|
||||||
public CustomReactionsModule()
|
public CustomReactionsModule()
|
||||||
{
|
{
|
||||||
commandFuncs = new Dictionary<string, Func<CommandEventArgs, string>>
|
commandFuncs = new Dictionary<Regex, Func<CommandEventArgs, Match, string>>
|
||||||
{
|
{
|
||||||
{"%rng%", (e) => rng.Next().ToString()},
|
{new Regex(@"(?:%rng%|%rng:(\d{1,9})-(\d{1,9})%)"), (e,m) => {
|
||||||
{"%mention%", (e) => NadekoBot.BotMention },
|
int start, end;
|
||||||
{"%user%", e => e.User.Mention },
|
if (m.Groups[1].Success)
|
||||||
{"%target%", e => e.GetArg("args")?.Trim() ?? "" },
|
{
|
||||||
|
start = int.Parse(m.Groups[1].Value);
|
||||||
|
end = int.Parse(m.Groups[2].Value);
|
||||||
|
return rng.Next(start, end).ToString();
|
||||||
|
}else return rng.Next().ToString();
|
||||||
|
} },
|
||||||
|
{new Regex("%mention%"), (e,m) => NadekoBot.BotMention },
|
||||||
|
{new Regex("%user%"), (e,m) => e.User.Mention },
|
||||||
|
{new Regex("%target%"), (e,m) => e.GetArg("args")?.Trim() ?? "" },
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Install(ModuleManager manager)
|
public override void Install(ModuleManager manager)
|
||||||
{
|
{
|
||||||
|
|
||||||
manager.CreateCommands("", cgb =>
|
manager.CreateCommands("", cgb =>
|
||||||
{
|
{
|
||||||
|
|
||||||
cgb.AddCheck(PermissionChecker.Instance);
|
cgb.AddCheck(PermissionChecker.Instance);
|
||||||
|
|
||||||
foreach (var command in NadekoBot.Config.CustomReactions)
|
foreach (var command in NadekoBot.Config.CustomReactions)
|
||||||
@ -47,11 +55,12 @@ namespace NadekoBot.Modules.CustomReactions
|
|||||||
.Do(async e =>
|
.Do(async e =>
|
||||||
{
|
{
|
||||||
string str = command.Value[rng.Next(0, command.Value.Count())];
|
string str = command.Value[rng.Next(0, command.Value.Count())];
|
||||||
commandFuncs.Keys.ForEach(k => str = str.Replace(k, commandFuncs[k](e)));
|
commandFuncs.Keys.ForEach(key => str = key.Replace(str, m => commandFuncs[key](e, m)));
|
||||||
|
|
||||||
|
|
||||||
await e.Channel.SendMessage(str).ConfigureAwait(false);
|
await e.Channel.SendMessage(str).ConfigureAwait(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user