more patting, better nullchecks, commschannel, greeted stats

osu stuff coming one of these days
This commit is contained in:
Master Kwoth 2016-02-02 15:53:01 +01:00
parent 4938b1b5fe
commit f1cfad1556
7 changed files with 59 additions and 25 deletions

View File

@ -12,7 +12,7 @@ namespace NadekoBot
{ {
public class NadekoStats public class NadekoStats
{ {
public string BotVersion = "0.8-beta4.2"; public string BotVersion = "0.8-beta5";
private static readonly NadekoStats _instance = new NadekoStats(); private static readonly NadekoStats _instance = new NadekoStats();
public static NadekoStats Instance => _instance; public static NadekoStats Instance => _instance;
@ -57,8 +57,9 @@ namespace NadekoBot
$"\n`Servers: {_client.Servers.Count()}`" + $"\n`Servers: {_client.Servers.Count()}`" +
$"\n`Channels: {_client.Servers.Sum(s => s.AllChannels.Count())}`" + $"\n`Channels: {_client.Servers.Sum(s => s.AllChannels.Count())}`" +
//$"\nUsers: {_client.Servers.SelectMany(x => x.Users.Select(y => y.Id)).Count()} (non-unique)" + //$"\nUsers: {_client.Servers.SelectMany(x => x.Users.Select(y => y.Id)).Count()} (non-unique)" +
//$"\nHeap: {Math.Round(GC.GetTotalMemory(true) / (1024.0 * 1024.0), 2).ToString()}MB" + $"\n`Heap: {Math.Round((double)GC.GetTotalMemory(true) / 1.MiB(), 2).ToString()} MB`" +
$"\n`Commands Ran this session: {_commandsRan}`"; $"\n`Commands Ran this session: {_commandsRan}`" +
$"\n`Greeted/Byed {Commands.ServerGreetCommand.Greeted} times.`";
} }
public string GetStats() { public string GetStats() {

View File

@ -11,6 +11,7 @@
public string ParseKey; public string ParseKey;
public string TrelloAppKey; public string TrelloAppKey;
public bool? ForwardMessages; public bool? ForwardMessages;
public string OsuApiKey;
} }
public class AnimeResult public class AnimeResult
{ {

View File

@ -28,6 +28,8 @@ namespace NadekoBot.Commands {
public static ConcurrentDictionary<ulong, AnnounceControls> AnnouncementsDictionary; public static ConcurrentDictionary<ulong, AnnounceControls> AnnouncementsDictionary;
public static long Greeted = 0;
public ServerGreetCommand() : base() { public ServerGreetCommand() : base() {
AnnouncementsDictionary = new ConcurrentDictionary<ulong, AnnounceControls>(); AnnouncementsDictionary = new ConcurrentDictionary<ulong, AnnounceControls>();
@ -52,6 +54,7 @@ namespace NadekoBot.Commands {
var msg = controls.GreetText.Replace("%user%", e.User.Mention).Trim(); var msg = controls.GreetText.Replace("%user%", e.User.Mention).Trim();
if (string.IsNullOrEmpty(msg)) if (string.IsNullOrEmpty(msg))
return; return;
Greeted++;
await channel.Send(msg); await channel.Send(msg);
} }
@ -66,6 +69,7 @@ namespace NadekoBot.Commands {
var msg = controls.GreetText.Replace("%user%", e.User.Mention).Trim(); var msg = controls.GreetText.Replace("%user%", e.User.Mention).Trim();
if (string.IsNullOrEmpty(msg)) if (string.IsNullOrEmpty(msg))
return; return;
Greeted++;
await channel.Send(msg); await channel.Send(msg);
} }

View File

@ -448,17 +448,19 @@ namespace NadekoBot.Modules {
Server commsServer = null; Server commsServer = null;
User commsUser = null; User commsUser = null;
Channel commsChannel = null;
cgb.CreateCommand(".commsuser") cgb.CreateCommand(".commsuser")
.Description("Sets a user for through-bot communication. Only works if server is set.**Owner only**.") .Description("Sets a user for through-bot communication. Only works if server is set. Resets commschannel.**Owner only**.")
.Parameter("name", ParameterType.Unparsed) .Parameter("name", ParameterType.Unparsed)
.Do(async e => { .Do(async e => {
if (e.User.Id != NadekoBot.OwnerID) return; if (e.User.Id != NadekoBot.OwnerID) return;
commsUser = commsServer?.FindUsers(e.GetArg("name")).FirstOrDefault(); commsUser = commsServer?.FindUsers(e.GetArg("name")).FirstOrDefault();
if (commsUser != null) if (commsUser != null) {
commsChannel = null;
await e.Send("User for comms set."); await e.Send("User for comms set.");
else } else
await e.Send("No such user."); await e.Send("No server specified or user.");
}); });
cgb.CreateCommand(".commsserver") cgb.CreateCommand(".commsserver")
@ -473,13 +475,29 @@ namespace NadekoBot.Modules {
await e.Send("No such server."); await e.Send("No such server.");
}); });
cgb.CreateCommand(".commschannel")
.Description("Sets a channel for through-bot communication. Only works if server is set. Resets commsuser.**Owner only**.")
.Parameter("ch", ParameterType.Unparsed)
.Do(async e => {
if (e.User.Id != NadekoBot.OwnerID) return;
commsChannel = commsServer?.FindChannels(e.GetArg("ch")).FirstOrDefault();
if (commsServer != null) {
commsUser = null;
await e.Send("Server for comms set.");
} else
await e.Send("No server specified or channel is invalid.");
});
cgb.CreateCommand(".send") cgb.CreateCommand(".send")
.Description("Send a message to someone on a different server through the bot.**Owner only.**\n **Usage**: .send Message text multi word!") .Description("Send a message to someone on a different server through the bot.**Owner only.**\n **Usage**: .send Message text multi word!")
.Parameter("msg", ParameterType.Unparsed) .Parameter("msg", ParameterType.Unparsed)
.Do(async e => { .Do(async e => {
if (e.User.Id != NadekoBot.OwnerID) return; if (e.User.Id != NadekoBot.OwnerID) return;
try { try {
await commsUser.SendMessage(e.GetArg("msg")); if (commsUser != null)
await commsUser.SendMessage(e.GetArg("msg"));
else if (commsChannel != null)
await commsChannel.SendMessage(e.GetArg("msg"));
} catch (Exception) { } catch (Exception) {
await e.Send("Sending failed."); await e.Send("Sending failed.");
} }

View File

@ -192,8 +192,11 @@ namespace NadekoBot.Modules {
.Do(async e => { .Do(async e => {
var user = e.GetArg("user"); var user = e.GetArg("user");
if (user == null || e.Message.MentionedUsers.Count() == 0) return; if (user == null || e.Message.MentionedUsers.Count() == 0) return;
string[] pats = new string[] { "http://i.imgur.com/IiQwK12.gif",
await e.Send($"{e.Message.MentionedUsers.First().Mention} http://i.imgur.com/eOJlnwP.gif"); "http://i.imgur.com/JCXj8yD.gif",
"http://i.imgur.com/qqBl2bm.gif",
"http://i.imgur.com/eOJlnwP.gif" };
await e.Send($"{e.Message.MentionedUsers.First().Mention} {pats[new Random().Next(0, pats.Length)]}");
}); });
cgb.CreateCommand("are you real") cgb.CreateCommand("are you real")
@ -341,7 +344,7 @@ namespace NadekoBot.Modules {
.Description("Useless. Writes calling @X to chat.\n**Usage**: @NadekoBot call @X ") .Description("Useless. Writes calling @X to chat.\n**Usage**: @NadekoBot call @X ")
.Parameter("who", ParameterType.Required) .Parameter("who", ParameterType.Required)
.Do(async e => { .Do(async e => {
await e.Send("Calling " + e.Args[0] + "..."); await e.Send("Calling " + e.Args[0].Replace("@everyone","[everyone]") + "...");
}); });
cgb.CreateCommand("hide") cgb.CreateCommand("hide")
.Description("Hides nadeko in plain sight!11!!") .Description("Hides nadeko in plain sight!11!!")

View File

@ -12,13 +12,16 @@ using NadekoBot.Extensions;
namespace NadekoBot.Modules { namespace NadekoBot.Modules {
class Searches : DiscordModule { class Searches : DiscordModule {
public Searches() : base() { public Searches() : base() {
// commands.Add(new OsuCommands());
} }
public override void Install(ModuleManager manager) { public override void Install(ModuleManager manager) {
var client = NadekoBot.client; var client = NadekoBot.client;
manager.CreateCommands("", cgb => { manager.CreateCommands("", cgb => {
commands.ForEach(cmd => cmd.Init(cgb));
cgb.CreateCommand("~yt") cgb.CreateCommand("~yt")
.Parameter("query", Discord.Commands.ParameterType.Unparsed) .Parameter("query", Discord.Commands.ParameterType.Unparsed)
.Description("Queries youtubes and embeds the first result") .Description("Queries youtubes and embeds the first result")

View File

@ -20,44 +20,48 @@ namespace NadekoBot {
public static string password; public static string password;
public static string TrelloAppKey; public static string TrelloAppKey;
public static bool ForwardMessages = false; public static bool ForwardMessages = false;
public static Credentials creds;
static void Main() { static void Main() {
//load credentials from credentials.json //load credentials from credentials.json
Credentials c;
bool loadTrello = false; bool loadTrello = false;
try { try {
c = JsonConvert.DeserializeObject<Credentials>(File.ReadAllText("credentials.json")); creds = JsonConvert.DeserializeObject<Credentials>(File.ReadAllText("credentials.json"));
botMention = c.BotMention; botMention = creds.BotMention;
if (c.GoogleAPIKey == null || c.GoogleAPIKey == "") { if (string.IsNullOrWhiteSpace(creds.GoogleAPIKey)) {
Console.WriteLine("No google api key found. You will not be able to use music and links won't be shortened."); Console.WriteLine("No google api key found. You will not be able to use music and links won't be shortened.");
} else { } else {
Console.WriteLine("Google API key provided."); Console.WriteLine("Google API key provided.");
GoogleAPIKey = c.GoogleAPIKey; GoogleAPIKey = creds.GoogleAPIKey;
} }
if (c.TrelloAppKey == null || c.TrelloAppKey == "") { if (string.IsNullOrWhiteSpace(creds.TrelloAppKey)) {
Console.WriteLine("No trello appkey found. You will not be able to use trello commands."); Console.WriteLine("No trello appkey found. You will not be able to use trello commands.");
} else { } else {
Console.WriteLine("Trello app key provided."); Console.WriteLine("Trello app key provided.");
TrelloAppKey = c.TrelloAppKey; TrelloAppKey = creds.TrelloAppKey;
loadTrello = true; loadTrello = true;
} }
if (c.ForwardMessages != true) if (creds.ForwardMessages != true)
Console.WriteLine("Not forwarding messages."); Console.WriteLine("Not forwarding messages.");
else { else {
ForwardMessages = true; ForwardMessages = true;
Console.WriteLine("Forwarding messages."); Console.WriteLine("Forwarding messages.");
} }
if (c.ParseKey == null || c.ParseID == null || c.ParseID == "" || c.ParseKey == "") { if (string.IsNullOrWhiteSpace(creds.ParseID) || string.IsNullOrWhiteSpace(creds.ParseKey)) {
Console.WriteLine("Parse key and/or ID not found. Those are mandatory."); Console.WriteLine("Parse key and/or ID not found. Those are mandatory.");
Console.ReadKey(); Console.ReadKey();
return; return;
} }
if(string.IsNullOrWhiteSpace(creds.OsuApiKey))
Console.WriteLine("No osu API key found. Osu functionality is disabled.");
else
Console.WriteLine("Osu enabled.");
//init parse //init parse
ParseClient.Initialize(c.ParseID, c.ParseKey); ParseClient.Initialize(creds.ParseID, creds.ParseKey);
OwnerID = c.OwnerID; OwnerID = creds.OwnerID;
password = c.Password; password = creds.Password;
} catch (Exception ex) { } catch (Exception ex) {
Console.WriteLine($"Failed to load stuff from credentials.json, RTFM\n{ex.Message}"); Console.WriteLine($"Failed to load stuff from credentials.json, RTFM\n{ex.Message}");
Console.ReadKey(); Console.ReadKey();
@ -103,7 +107,7 @@ namespace NadekoBot {
//run the bot //run the bot
client.ExecuteAndWait(async () => { client.ExecuteAndWait(async () => {
await client.Connect(c.Username, c.Password); await client.Connect(creds.Username, creds.Password);
Console.WriteLine("-----------------"); Console.WriteLine("-----------------");
Console.WriteLine(NadekoStats.Instance.GetStats()); Console.WriteLine(NadekoStats.Instance.GetStats());
Console.WriteLine("-----------------"); Console.WriteLine("-----------------");