RIP & FAQ
This commit is contained in:
parent
b37ecf80e4
commit
9423e7887d
@ -8,6 +8,7 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace NadekoBot.Extensions
|
namespace NadekoBot.Extensions
|
||||||
@ -180,6 +181,52 @@ namespace NadekoBot.Extensions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string GetOnPage<T>(this IEnumerable<T> source, int pageIndex, int itemsPerPage = 5)
|
||||||
|
{
|
||||||
|
var items = source.Skip(pageIndex * itemsPerPage).Take(itemsPerPage);
|
||||||
|
if (!items.Any())
|
||||||
|
{
|
||||||
|
return $"No items on page {pageIndex + 1}.";
|
||||||
|
}
|
||||||
|
var sb = new StringBuilder($"---page {pageIndex + 1} --\n");
|
||||||
|
var itemsDC = items as IEnumerable<KeyValuePair<string, IEnumerable<string>>>;
|
||||||
|
var itemsDS = items as IEnumerable<KeyValuePair<string, string>>;
|
||||||
|
if (itemsDC != null)
|
||||||
|
{
|
||||||
|
foreach (var item in itemsDC)
|
||||||
|
{
|
||||||
|
sb.Append($"{ Format.Code(item.Key)}\n");
|
||||||
|
int i = 1;
|
||||||
|
var last = item.Value.Last();
|
||||||
|
foreach (var value in item.Value)
|
||||||
|
{
|
||||||
|
if (last != value)
|
||||||
|
sb.AppendLine(" `├" + i++ + "─`" + Format.Bold(value));
|
||||||
|
else
|
||||||
|
sb.AppendLine(" `└" + i++ + "─`" + Format.Bold(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (itemsDS != null)
|
||||||
|
{
|
||||||
|
foreach (var item in itemsDS)
|
||||||
|
{
|
||||||
|
sb.Append($"{ Format.Code(item.Key)}\n");
|
||||||
|
sb.AppendLine(" `└─`" + Format.Bold(item.Value));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (var item in items)
|
||||||
|
{
|
||||||
|
sb.Append($"{ Format.Code(item.ToString())} \n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the program runtime
|
/// Gets the program runtime
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Discord.Modules;
|
using Discord.Modules;
|
||||||
using NadekoBot.Classes;
|
using NadekoBot.Classes;
|
||||||
@ -198,11 +198,11 @@ namespace NadekoBot.Modules.Conversations
|
|||||||
var text = "";
|
var text = "";
|
||||||
var avatar = await GetAvatar(usr.AvatarUrl);
|
var avatar = await GetAvatar(usr.AvatarUrl);
|
||||||
text = usr?.Name ?? e.GetArg("user");
|
text = usr?.Name ?? e.GetArg("user");
|
||||||
await e.Channel.SendFile("ripzor_m8.png",
|
var file = RipUser(text, avatar, string.IsNullOrWhiteSpace(e.GetArg("year"))
|
||||||
RipUser(text, avatar, string.IsNullOrWhiteSpace(e.GetArg("year"))
|
|
||||||
? null
|
? null
|
||||||
: e.GetArg("year")))
|
: e.GetArg("year"));
|
||||||
.ConfigureAwait(false);
|
await e.Channel.SendFile("ripzor_m8.png",
|
||||||
|
file);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!NadekoBot.Config.DontJoinServers)
|
if (!NadekoBot.Config.DontJoinServers)
|
||||||
@ -343,29 +343,13 @@ namespace NadekoBot.Modules.Conversations
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public Stream RipName(string name, string year = null)
|
/// <summary>
|
||||||
{
|
/// Create a RIP image of the given name and avatar, with an optional year
|
||||||
var bm = Resources.rip;
|
/// </summary>
|
||||||
|
/// <param name="name"></param>
|
||||||
var offset = name.Length * 5;
|
/// <param name="avatar"></param>
|
||||||
|
/// <param name="year"></param>
|
||||||
var fontSize = 20;
|
/// <returns></returns>
|
||||||
|
|
||||||
if (name.Length > 10)
|
|
||||||
{
|
|
||||||
fontSize -= (name.Length - 10) / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO use measure string
|
|
||||||
var g = Graphics.FromImage(bm);
|
|
||||||
g.DrawString(name, new Font("Comic Sans MS", fontSize, FontStyle.Bold), Brushes.Black, 100 - offset, 200);
|
|
||||||
g.DrawString((year ?? "?") + " - " + DateTime.Now.Year, new Font("Consolas", 12, FontStyle.Bold), Brushes.Black, 80, 235);
|
|
||||||
g.Flush();
|
|
||||||
g.Dispose();
|
|
||||||
|
|
||||||
return bm.ToStream(ImageFormat.Png);
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
||||||
@ -386,7 +370,7 @@ namespace NadekoBot.Modules.Conversations
|
|||||||
g.DrawString(name, new Font("Comic Sans MS", fontSize, FontStyle.Bold), Brushes.Black, 100 - offset, 220);
|
g.DrawString(name, new Font("Comic Sans MS", fontSize, FontStyle.Bold), Brushes.Black, 100 - offset, 220);
|
||||||
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);
|
||||||
g.DrawImage((Image)Resources.rose_overlay, 0, 0);
|
g.DrawImage((Image)Resources.rose_overlay, 0, 0);
|
||||||
g.Flush();
|
g.Flush();
|
||||||
g.Dispose();
|
g.Dispose();
|
||||||
@ -402,7 +386,7 @@ namespace NadekoBot.Modules.Conversations
|
|||||||
Bitmap bmp = new Bitmap(100, 100);
|
Bitmap bmp = new Bitmap(100, 100);
|
||||||
using (GraphicsPath gp = new GraphicsPath())
|
using (GraphicsPath gp = new GraphicsPath())
|
||||||
{
|
{
|
||||||
gp.AddEllipse(0,0, bmp.Width, bmp.Height);
|
gp.AddEllipse(0, 0, bmp.Width, bmp.Height);
|
||||||
using (Graphics gr = Graphics.FromImage(bmp))
|
using (Graphics gr = Graphics.FromImage(bmp))
|
||||||
{
|
{
|
||||||
gr.SetClip(gp);
|
gr.SetClip(gp);
|
||||||
|
@ -4,6 +4,7 @@ using NadekoBot.Classes.Help.Commands;
|
|||||||
using NadekoBot.Extensions;
|
using NadekoBot.Extensions;
|
||||||
using NadekoBot.Modules.Permissions.Classes;
|
using NadekoBot.Modules.Permissions.Classes;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace NadekoBot.Modules.Help
|
namespace NadekoBot.Modules.Help
|
||||||
{
|
{
|
||||||
@ -17,6 +18,8 @@ namespace NadekoBot.Modules.Help
|
|||||||
|
|
||||||
public override string Prefix { get; } = NadekoBot.Config.CommandPrefixes.Help;
|
public override string Prefix { get; } = NadekoBot.Config.CommandPrefixes.Help;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public override void Install(ModuleManager manager)
|
public override void Install(ModuleManager manager)
|
||||||
{
|
{
|
||||||
manager.CreateCommands("", cgb =>
|
manager.CreateCommands("", cgb =>
|
||||||
@ -50,6 +53,37 @@ namespace NadekoBot.Modules.Help
|
|||||||
await e.Channel.SendMessage("`List of commands:` \n• " + string.Join("\n• ", cmdsArray.Select(c => c.Text)))
|
await e.Channel.SendMessage("`List of commands:` \n• " + string.Join("\n• ", cmdsArray.Select(c => c.Text)))
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
});
|
});
|
||||||
|
cgb.CreateCommand(Prefix + "faq")
|
||||||
|
.Description("Browse the FAQ\n**Usage**: `-faq 1` `-faq Q5`")
|
||||||
|
.Parameter("index", ParameterType.Unparsed)
|
||||||
|
.Do(async e =>
|
||||||
|
{
|
||||||
|
string message = "Something went wrong";
|
||||||
|
string indexString = e.GetArg("index")?.Trim().ToLowerInvariant();
|
||||||
|
Regex questiona = new Regex(@"q(uestion)?\s*(?<number>\d+)");
|
||||||
|
var m = questiona.Match(indexString);
|
||||||
|
if (m.Success)
|
||||||
|
{
|
||||||
|
int index;
|
||||||
|
if (!int.TryParse(m.Groups["number"].Value, out index) || index < 1|| index > NadekoBot.Config.FAQ.Count)
|
||||||
|
{
|
||||||
|
message = "Valid index required";
|
||||||
|
await e.Channel.SendMessage(message).ConfigureAwait(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var question = NadekoBot.Config.FAQ.Skip(--index).FirstOrDefault();
|
||||||
|
message = Discord.Format.Bold(question.Key) + "\n\n" + Discord.Format.Italics(question.Value);
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int index;
|
||||||
|
if (!int.TryParse(indexString, out index) || index < 0) index =1;
|
||||||
|
message = NadekoBot.Config.FAQ.GetOnPage(--index);
|
||||||
|
}
|
||||||
|
await e.Channel.SendMessage(message).ConfigureAwait(false);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,6 +91,11 @@ namespace NadekoBot.Classes.JSONModels
|
|||||||
} }
|
} }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public Dictionary<string, string> FAQ = new Dictionary<string, string>()
|
||||||
|
{
|
||||||
|
{"Q1: Does Nadeko have music?", "A: The official Nadeko currently does not have music, which means you'll have to host a version yourself (see Q2)" }
|
||||||
|
};
|
||||||
|
|
||||||
public List<string> RotatingStatuses { get; set; } = new List<string>();
|
public List<string> RotatingStatuses { get; set; } = new List<string>();
|
||||||
public CommandPrefixesModel CommandPrefixes { get; set; } = new CommandPrefixesModel();
|
public CommandPrefixesModel CommandPrefixes { get; set; } = new CommandPrefixesModel();
|
||||||
public HashSet<ulong> ServerBlacklist { get; set; } = new HashSet<ulong>();
|
public HashSet<ulong> ServerBlacklist { get; set; } = new HashSet<ulong>();
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
{
|
{
|
||||||
|
"FAQ": {
|
||||||
|
"Q1: Does Nadeko have music?": "A: The official Nadeko currently does not have music, which means you'll have to host a version yourself (see Q2)"
|
||||||
|
},
|
||||||
"DontJoinServers": false,
|
"DontJoinServers": false,
|
||||||
"ForwardMessages": true,
|
"ForwardMessages": true,
|
||||||
"IsRotatingStatus": false,
|
"IsRotatingStatus": false,
|
||||||
|
Loading…
Reference in New Issue
Block a user