more patting, better nullchecks, commschannel, greeted stats
osu stuff coming one of these days
This commit is contained in:
parent
4938b1b5fe
commit
f1cfad1556
@ -12,7 +12,7 @@ namespace NadekoBot
|
||||
{
|
||||
public class NadekoStats
|
||||
{
|
||||
public string BotVersion = "0.8-beta4.2";
|
||||
public string BotVersion = "0.8-beta5";
|
||||
|
||||
private static readonly NadekoStats _instance = new NadekoStats();
|
||||
public static NadekoStats Instance => _instance;
|
||||
@ -57,8 +57,9 @@ namespace NadekoBot
|
||||
$"\n`Servers: {_client.Servers.Count()}`" +
|
||||
$"\n`Channels: {_client.Servers.Sum(s => s.AllChannels.Count())}`" +
|
||||
//$"\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`Commands Ran this session: {_commandsRan}`";
|
||||
$"\n`Heap: {Math.Round((double)GC.GetTotalMemory(true) / 1.MiB(), 2).ToString()} MB`" +
|
||||
$"\n`Commands Ran this session: {_commandsRan}`" +
|
||||
$"\n`Greeted/Byed {Commands.ServerGreetCommand.Greeted} times.`";
|
||||
}
|
||||
|
||||
public string GetStats() {
|
||||
|
@ -11,6 +11,7 @@
|
||||
public string ParseKey;
|
||||
public string TrelloAppKey;
|
||||
public bool? ForwardMessages;
|
||||
public string OsuApiKey;
|
||||
}
|
||||
public class AnimeResult
|
||||
{
|
||||
|
@ -28,6 +28,8 @@ namespace NadekoBot.Commands {
|
||||
|
||||
public static ConcurrentDictionary<ulong, AnnounceControls> AnnouncementsDictionary;
|
||||
|
||||
public static long Greeted = 0;
|
||||
|
||||
public ServerGreetCommand() : base() {
|
||||
AnnouncementsDictionary = new ConcurrentDictionary<ulong, AnnounceControls>();
|
||||
|
||||
@ -52,6 +54,7 @@ namespace NadekoBot.Commands {
|
||||
var msg = controls.GreetText.Replace("%user%", e.User.Mention).Trim();
|
||||
if (string.IsNullOrEmpty(msg))
|
||||
return;
|
||||
Greeted++;
|
||||
await channel.Send(msg);
|
||||
}
|
||||
|
||||
@ -66,6 +69,7 @@ namespace NadekoBot.Commands {
|
||||
var msg = controls.GreetText.Replace("%user%", e.User.Mention).Trim();
|
||||
if (string.IsNullOrEmpty(msg))
|
||||
return;
|
||||
Greeted++;
|
||||
await channel.Send(msg);
|
||||
}
|
||||
|
||||
|
@ -448,17 +448,19 @@ namespace NadekoBot.Modules {
|
||||
|
||||
Server commsServer = null;
|
||||
User commsUser = null;
|
||||
Channel commsChannel = null;
|
||||
|
||||
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)
|
||||
.Do(async e => {
|
||||
if (e.User.Id != NadekoBot.OwnerID) return;
|
||||
commsUser = commsServer?.FindUsers(e.GetArg("name")).FirstOrDefault();
|
||||
if (commsUser != null)
|
||||
if (commsUser != null) {
|
||||
commsChannel = null;
|
||||
await e.Send("User for comms set.");
|
||||
else
|
||||
await e.Send("No such user.");
|
||||
} else
|
||||
await e.Send("No server specified or user.");
|
||||
});
|
||||
|
||||
cgb.CreateCommand(".commsserver")
|
||||
@ -473,13 +475,29 @@ namespace NadekoBot.Modules {
|
||||
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")
|
||||
.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)
|
||||
.Do(async e => {
|
||||
if (e.User.Id != NadekoBot.OwnerID) return;
|
||||
try {
|
||||
if (commsUser != null)
|
||||
await commsUser.SendMessage(e.GetArg("msg"));
|
||||
else if (commsChannel != null)
|
||||
await commsChannel.SendMessage(e.GetArg("msg"));
|
||||
} catch (Exception) {
|
||||
await e.Send("Sending failed.");
|
||||
}
|
||||
|
@ -192,8 +192,11 @@ namespace NadekoBot.Modules {
|
||||
.Do(async e => {
|
||||
var user = e.GetArg("user");
|
||||
if (user == null || e.Message.MentionedUsers.Count() == 0) return;
|
||||
|
||||
await e.Send($"{e.Message.MentionedUsers.First().Mention} http://i.imgur.com/eOJlnwP.gif");
|
||||
string[] pats = new string[] { "http://i.imgur.com/IiQwK12.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")
|
||||
@ -341,7 +344,7 @@ namespace NadekoBot.Modules {
|
||||
.Description("Useless. Writes calling @X to chat.\n**Usage**: @NadekoBot call @X ")
|
||||
.Parameter("who", ParameterType.Required)
|
||||
.Do(async e => {
|
||||
await e.Send("Calling " + e.Args[0] + "...");
|
||||
await e.Send("Calling " + e.Args[0].Replace("@everyone","[everyone]") + "...");
|
||||
});
|
||||
cgb.CreateCommand("hide")
|
||||
.Description("Hides nadeko in plain sight!11!!")
|
||||
|
@ -12,13 +12,16 @@ using NadekoBot.Extensions;
|
||||
namespace NadekoBot.Modules {
|
||||
class Searches : DiscordModule {
|
||||
public Searches() : base() {
|
||||
|
||||
// commands.Add(new OsuCommands());
|
||||
}
|
||||
|
||||
public override void Install(ModuleManager manager) {
|
||||
var client = NadekoBot.client;
|
||||
|
||||
manager.CreateCommands("", cgb => {
|
||||
|
||||
commands.ForEach(cmd => cmd.Init(cgb));
|
||||
|
||||
cgb.CreateCommand("~yt")
|
||||
.Parameter("query", Discord.Commands.ParameterType.Unparsed)
|
||||
.Description("Queries youtubes and embeds the first result")
|
||||
|
@ -20,44 +20,48 @@ namespace NadekoBot {
|
||||
public static string password;
|
||||
public static string TrelloAppKey;
|
||||
public static bool ForwardMessages = false;
|
||||
public static Credentials creds;
|
||||
|
||||
static void Main() {
|
||||
//load credentials from credentials.json
|
||||
Credentials c;
|
||||
bool loadTrello = false;
|
||||
try {
|
||||
c = JsonConvert.DeserializeObject<Credentials>(File.ReadAllText("credentials.json"));
|
||||
botMention = c.BotMention;
|
||||
if (c.GoogleAPIKey == null || c.GoogleAPIKey == "") {
|
||||
creds = JsonConvert.DeserializeObject<Credentials>(File.ReadAllText("credentials.json"));
|
||||
botMention = creds.BotMention;
|
||||
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.");
|
||||
} else {
|
||||
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.");
|
||||
} else {
|
||||
Console.WriteLine("Trello app key provided.");
|
||||
TrelloAppKey = c.TrelloAppKey;
|
||||
TrelloAppKey = creds.TrelloAppKey;
|
||||
loadTrello = true;
|
||||
}
|
||||
if (c.ForwardMessages != true)
|
||||
if (creds.ForwardMessages != true)
|
||||
Console.WriteLine("Not forwarding messages.");
|
||||
else {
|
||||
ForwardMessages = true;
|
||||
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.ReadKey();
|
||||
return;
|
||||
}
|
||||
if(string.IsNullOrWhiteSpace(creds.OsuApiKey))
|
||||
Console.WriteLine("No osu API key found. Osu functionality is disabled.");
|
||||
else
|
||||
Console.WriteLine("Osu enabled.");
|
||||
|
||||
//init parse
|
||||
ParseClient.Initialize(c.ParseID, c.ParseKey);
|
||||
ParseClient.Initialize(creds.ParseID, creds.ParseKey);
|
||||
|
||||
OwnerID = c.OwnerID;
|
||||
password = c.Password;
|
||||
OwnerID = creds.OwnerID;
|
||||
password = creds.Password;
|
||||
} catch (Exception ex) {
|
||||
Console.WriteLine($"Failed to load stuff from credentials.json, RTFM\n{ex.Message}");
|
||||
Console.ReadKey();
|
||||
@ -103,7 +107,7 @@ namespace NadekoBot {
|
||||
|
||||
//run the bot
|
||||
client.ExecuteAndWait(async () => {
|
||||
await client.Connect(c.Username, c.Password);
|
||||
await client.Connect(creds.Username, creds.Password);
|
||||
Console.WriteLine("-----------------");
|
||||
Console.WriteLine(NadekoStats.Instance.GetStats());
|
||||
Console.WriteLine("-----------------");
|
||||
|
Loading…
Reference in New Issue
Block a user