new libs, crashfix, !m setgame, ripyear...

also better strings for music (plural and singular)
This commit is contained in:
Master Kwoth
2016-01-31 09:22:47 +01:00
parent 73309c723e
commit e71e390cca
10 changed files with 64 additions and 35 deletions

View File

@ -222,17 +222,14 @@ namespace NadekoBot.Modules {
});
cgb.CreateCommand("rip")
.Description("Shows a grave image.Optional parameter [@X] instructs her to put X's name on the grave.\n**Usage**: @NadekoBot rip [@X]")
.Parameter("user", ParameterType.Unparsed)
.Description("Shows a grave image of someone with a start year\n**Usage**: @NadekoBot rip @Someone 2000")
.Parameter("user", ParameterType.Optional)
.Parameter("year", ParameterType.Optional)
.Do(async e => {
var usr = e.Channel.FindUsers(e.GetArg("user")).FirstOrDefault();
string text = "";
if (usr == null) {
text = e.GetArg("user");
} else {
text = usr.Name;
}
await e.Channel.SendFile("ripzor_m8.png", RipName(text));
text = usr?.Name;
await e.Channel.SendFile("ripzor_m8.png", RipName(text, e.GetArg("year") == "" ? null : e.GetArg("year")));
});
cgb.CreateCommand("j")
@ -324,7 +321,7 @@ namespace NadekoBot.Modules {
.Do(async e => {
string str = "Bye";
foreach (var u in e.Message.MentionedUsers) {
if(u.Id != NadekoBot.client.CurrentUser.Id)
if (u.Id != NadekoBot.client.CurrentUser.Id)
str += " " + u.Mention;
}
await e.Send(str);
@ -406,7 +403,7 @@ namespace NadekoBot.Modules {
});
}
public Stream RipName(string name) {
public Stream RipName(string name, string year = null) {
Bitmap bm = Resources.rip;
int offset = name.Length * 5;
@ -420,7 +417,7 @@ namespace NadekoBot.Modules {
//TODO use measure string
Graphics g = Graphics.FromImage(bm);
g.DrawString(name, new Font("Comic Sans MS", fontSize, FontStyle.Bold), Brushes.Black, 100 - offset, 200);
g.DrawString("? - " + DateTime.Now.Year, new Font("Consolas", 12, FontStyle.Bold), Brushes.Black, 80, 235);
g.DrawString((year == null ? "?" : year) + " - " + DateTime.Now.Year, new Font("Consolas", 12, FontStyle.Bold), Brushes.Black, 80, 235);
g.Flush();
g.Dispose();

View File

@ -14,11 +14,9 @@ namespace NadekoBot.Modules {
public static ConcurrentDictionary<Server, MusicControls> musicPlayers = new ConcurrentDictionary<Server, MusicControls>();
internal static string GetMusicStats() {
var servers = 0;
var queued = 0;
var stats = musicPlayers.Where(kvp => kvp.Value?.SongQueue.Count > 0 || kvp.Value?.CurrentSong != null);
return $"Playing {stats.Count()} songs, {stats.Sum(kvp => kvp.Value?.SongQueue?.Count ?? 0)} queued.";
int cnt;
return $"Playing {cnt = stats.Count()} songs".SnPl(cnt)+$", {stats.Sum(kvp => kvp.Value?.SongQueue?.Count ?? 0)} queued.";
}
public Music() : base() {
@ -164,6 +162,25 @@ namespace NadekoBot.Modules {
player.SongQueue.Shuffle();
await e.Send(":musical_note: Songs shuffled!");
});
bool setgameEnabled = false;
Timer setgameTimer = new Timer();
setgameTimer.Interval = 20000;
setgameTimer.Elapsed += (s, e) => {
int num = musicPlayers.Count;
NadekoBot.client.SetGame($"{num} songs".SnPl(num) + $", {musicPlayers.Sum(kvp => kvp.Value.SongQueue.Count())} queued");
};
setgameTimer.Start();
cgb.CreateCommand("setgame")
.Description("Sets the game of the bot to the number of songs playing.**Owner only**")
.Do(e => {
if (NadekoBot.OwnerID != e.User.Id)
return;
setgameEnabled = !setgameEnabled;
if (setgameEnabled)
setgameTimer.Start();
else
setgameTimer.Stop();
});
});
}
}

View File

@ -225,13 +225,17 @@ namespace NadekoBot.Modules
Console.WriteLine("ERROR: No google api key found. Playing `Never gonna give you up`.");
return @"https://www.youtube.com/watch?v=dQw4w9WgXcQ";
}
WebRequest wr = WebRequest.Create("https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=1&q=" + Uri.EscapeDataString(v) + "&key=" + NadekoBot.GoogleAPIKey);
try {
WebRequest wr = WebRequest.Create("https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=1&q=" + Uri.EscapeDataString(v) + "&key=" + NadekoBot.GoogleAPIKey);
var sr = new StreamReader(wr.GetResponse().GetResponseStream());
var sr = new StreamReader(wr.GetResponse().GetResponseStream());
dynamic obj = JObject.Parse(sr.ReadToEnd());
string toReturn = "http://www.youtube.com/watch?v=" + obj.items[0].id.videoId.ToString();
return toReturn;
dynamic obj = JObject.Parse(sr.ReadToEnd());
string toReturn = "http://www.youtube.com/watch?v=" + obj.items[0].id.videoId.ToString();
return toReturn;
} catch (Exception) {
return string.Empty;
}
}
public string GetDanbooruImageLink(string tag) {