lq, q nicer txt, fixed .prune > 100
This commit is contained in:
parent
171d3cd4ab
commit
efc2810f22
@ -33,6 +33,17 @@ namespace NadekoBot.Extensions {
|
|||||||
}
|
}
|
||||||
return "`"+string.Join(" ", letters)+"`";
|
return "`"+string.Join(" ", letters)+"`";
|
||||||
}
|
}
|
||||||
|
public static string TrimTo(this string str, int num) {
|
||||||
|
if (num < 0)
|
||||||
|
throw new ArgumentException("TrimTo argument cannot be less than 0");
|
||||||
|
if (num == 0)
|
||||||
|
return String.Empty;
|
||||||
|
if (num <= 3)
|
||||||
|
return String.Join("", str.Select(c => '.'));
|
||||||
|
if (str.Length < num)
|
||||||
|
return str;
|
||||||
|
return string.Join("", str.Take(num - 3)) + "...";
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sends a message to the channel from which this command is called.
|
/// Sends a message to the channel from which this command is called.
|
||||||
|
@ -65,7 +65,7 @@ namespace NadekoBot.Classes.Music {
|
|||||||
if (video == null) // do something with this error
|
if (video == null) // do something with this error
|
||||||
throw new Exception("Could not load any video elements based on the query.");
|
throw new Exception("Could not load any video elements based on the query.");
|
||||||
|
|
||||||
Title = video.Title;
|
Title = video.Title.Substring(0,video.Title.Length-10); // removing trailing "- You Tube"
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
privateState = StreamState.Completed;
|
privateState = StreamState.Completed;
|
||||||
Console.WriteLine($"Failed resolving the link.{ex.Message}");
|
Console.WriteLine($"Failed resolving the link.{ex.Message}");
|
||||||
@ -142,7 +142,7 @@ namespace NadekoBot.Classes.Music {
|
|||||||
|
|
||||||
public string Stats() =>
|
public string Stats() =>
|
||||||
"--------------------------------\n" +
|
"--------------------------------\n" +
|
||||||
$"Music stats for {string.Join("", parent.Title.Take(parent.Title.Length > 20 ? 20 : parent.Title.Length))}\n" +
|
$"Music stats for {string.Join("", parent.Title.TrimTo(50))}\n" +
|
||||||
$"Server: {parent.Server.Name}\n" +
|
$"Server: {parent.Server.Name}\n" +
|
||||||
$"Length:{buffer.Length * 1.0f / 1.MB()}MB Status: {State}\n" +
|
$"Length:{buffer.Length * 1.0f / 1.MB()}MB Status: {State}\n" +
|
||||||
"--------------------------------\n";
|
"--------------------------------\n";
|
||||||
|
@ -5,7 +5,6 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Timers;
|
|
||||||
using NadekoBot.Extensions;
|
using NadekoBot.Extensions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
@ -3,35 +3,47 @@ using System.Threading.Tasks;
|
|||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Discord.Legacy;
|
using Discord.Legacy;
|
||||||
using NadekoBot.Extensions;
|
using NadekoBot.Extensions;
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
namespace NadekoBot
|
namespace NadekoBot {
|
||||||
{
|
class FlipCoinCommand : DiscordCommand {
|
||||||
class FlipCoinCommand : DiscordCommand
|
|
||||||
{
|
|
||||||
|
|
||||||
private Random _r;
|
private Random _r;
|
||||||
public FlipCoinCommand() : base()
|
public FlipCoinCommand() : base() {
|
||||||
{
|
|
||||||
_r = new Random();
|
_r = new Random();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Func<CommandEventArgs, Task> DoFunc() => async e =>
|
public override Func<CommandEventArgs, Task> DoFunc() => async e => {
|
||||||
{
|
|
||||||
int num = _r.Next(0, 2);
|
if (e.GetArg("count") == "") {
|
||||||
if (num == 1)
|
if (_r.Next(0, 2) == 1)
|
||||||
{
|
await e.Channel.SendFile("heads.png", Properties.Resources.heads.ToStream(System.Drawing.Imaging.ImageFormat.Png));
|
||||||
await e.Channel.SendFile("heads.png",Properties.Resources.heads.ToStream(System.Drawing.Imaging.ImageFormat.Png));
|
else
|
||||||
}
|
await e.Channel.SendFile("tails.png", Properties.Resources.tails.ToStream(System.Drawing.Imaging.ImageFormat.Png));
|
||||||
else
|
} else {
|
||||||
{
|
int result;
|
||||||
await e.Channel.SendFile("tails.png", Properties.Resources.tails.ToStream(System.Drawing.Imaging.ImageFormat.Png));
|
if (int.TryParse(e.GetArg("count"), out result)) {
|
||||||
|
if (result > 10)
|
||||||
|
result = 10;
|
||||||
|
Image[] imgs = new Image[result];
|
||||||
|
for (int i = 0; i < result; i++) {
|
||||||
|
imgs[i] = _r.Next(0, 2) == 0 ?
|
||||||
|
Properties.Resources.tails :
|
||||||
|
Properties.Resources.heads;
|
||||||
|
}
|
||||||
|
await e.Channel.SendFile($"{result} coins.png", imgs.Merge().ToStream(System.Drawing.Imaging.ImageFormat.Png));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await e.Send("Invalid number");
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
public override void Init(CommandGroupBuilder cgb)
|
public override void Init(CommandGroupBuilder cgb) {
|
||||||
{
|
|
||||||
cgb.CreateCommand("$flip")
|
cgb.CreateCommand("$flip")
|
||||||
.Description("Flips a coin, heads or tails, and shows an image of it.")
|
.Description("Flips coin(s) - heads or tails, and shows an image.\n**Usage**: `$flip` or `$flip 3`")
|
||||||
|
.Parameter("count", ParameterType.Optional)
|
||||||
.Do(DoFunc());
|
.Do(DoFunc());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -300,7 +300,14 @@ namespace NadekoBot.Modules {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
(await e.Channel.DownloadMessages(num)).ForEach(async m => await m.Delete());
|
var msgs = await e.Channel.DownloadMessages(100);
|
||||||
|
var lastmessage = e.Channel.Messages.LastOrDefault();
|
||||||
|
while (num > 0 && lastmessage!=null) {
|
||||||
|
msgs.ForEach(async m => await m.Delete());
|
||||||
|
num -= 100;
|
||||||
|
lastmessage = msgs.LastOrDefault();
|
||||||
|
msgs = await e.Channel.DownloadMessages(100, lastmessage?.Id);
|
||||||
|
}
|
||||||
} catch (Exception) { await e.Send("Failed pruning. Make sure the bot has correct permissions."); }
|
} catch (Exception) { await e.Send("Failed pruning. Make sure the bot has correct permissions."); }
|
||||||
|
|
||||||
});
|
});
|
||||||
@ -322,9 +329,7 @@ namespace NadekoBot.Modules {
|
|||||||
.Description("Clears some of nadeko's messages from the current channel.")
|
.Description("Clears some of nadeko's messages from the current channel.")
|
||||||
.Do(async e => {
|
.Do(async e => {
|
||||||
try {
|
try {
|
||||||
if (e.Channel.Messages.Count() < 50) {
|
await e.Channel.DownloadMessages(100);
|
||||||
await e.Channel.DownloadMessages(100);
|
|
||||||
}
|
|
||||||
|
|
||||||
e.Channel.Messages.Where(msg => msg.User.Id == client.CurrentUser.Id).ForEach(async m => await m.Delete());
|
e.Channel.Messages.Where(msg => msg.User.Id == client.CurrentUser.Id).ForEach(async m => await m.Delete());
|
||||||
|
|
||||||
|
@ -96,21 +96,22 @@ namespace NadekoBot.Modules {
|
|||||||
if (sr == null)
|
if (sr == null)
|
||||||
throw new NullReferenceException("StreamRequest is null.");
|
throw new NullReferenceException("StreamRequest is null.");
|
||||||
Message msg = null;
|
Message msg = null;
|
||||||
|
Message qmsg = null;
|
||||||
sr.OnQueued += async () => {
|
sr.OnQueued += async () => {
|
||||||
msg = await e.Send($":musical_note:**Queued** {sr.Title}");
|
qmsg = await e.Send($":musical_note:**Queued** {sr.Title.TrimTo(55)}");
|
||||||
};
|
};
|
||||||
sr.OnCompleted += async () => {
|
sr.OnCompleted += async () => {
|
||||||
await e.Send($":musical_note:**Finished playing** {sr.Title}");
|
await e.Send($":musical_note:**Finished playing** {sr.Title.TrimTo(55)}");
|
||||||
};
|
};
|
||||||
sr.OnStarted += async () => {
|
sr.OnStarted += async () => {
|
||||||
if (msg == null)
|
if (msg == null)
|
||||||
await e.Send($":musical_note:**Starting playback of** {sr.Title}");
|
await e.Send($":musical_note:**Playing ** {sr.Title.TrimTo(55)}");
|
||||||
else
|
else
|
||||||
await msg.Edit($":musical_note:**Starting playback of** {sr.Title}");
|
await msg.Edit($":musical_note:**Playing ** {sr.Title.TrimTo(55)}");
|
||||||
|
qmsg?.Delete();
|
||||||
};
|
};
|
||||||
sr.OnBuffering += async () => {
|
sr.OnBuffering += async () => {
|
||||||
if (msg != null)
|
msg = await e.Send($":musical_note:**Buffering...** {sr.Title.TrimTo(55)}");
|
||||||
msg = await e.Send($":musical_note:**Buffering the song**...{sr.Title}");
|
|
||||||
};
|
};
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
@ -127,7 +128,8 @@ namespace NadekoBot.Modules {
|
|||||||
var player = musicPlayers[e.Server];
|
var player = musicPlayers[e.Server];
|
||||||
|
|
||||||
await e.Send(":musical_note: " + player.SongQueue.Count + " videos currently queued.");
|
await e.Send(":musical_note: " + player.SongQueue.Count + " videos currently queued.");
|
||||||
await e.Send(string.Join("\n", player.SongQueue.Select(v => v.Title).Take(10)));
|
int number = 1;
|
||||||
|
await e.Send(string.Join("\n", player.SongQueue.Select(v => $"**#{number++}** {v.Title.TrimTo(60)}").Take(10)));
|
||||||
});
|
});
|
||||||
|
|
||||||
cgb.CreateCommand("np")
|
cgb.CreateCommand("np")
|
||||||
|
@ -9,8 +9,6 @@ using Discord.Modules;
|
|||||||
using Discord.Audio;
|
using Discord.Audio;
|
||||||
using NadekoBot.Extensions;
|
using NadekoBot.Extensions;
|
||||||
using System.Timers;
|
using System.Timers;
|
||||||
using System.Linq;
|
|
||||||
using System.Diagnostics;
|
|
||||||
|
|
||||||
namespace NadekoBot {
|
namespace NadekoBot {
|
||||||
class NadekoBot {
|
class NadekoBot {
|
||||||
@ -49,11 +47,19 @@ namespace NadekoBot {
|
|||||||
ForwardMessages = true;
|
ForwardMessages = true;
|
||||||
Console.WriteLine("Forwarding messages.");
|
Console.WriteLine("Forwarding messages.");
|
||||||
}
|
}
|
||||||
|
if (c.ParseKey == null || c.ParseID == null || c.ParseID == "" || c.ParseKey == "") {
|
||||||
|
Console.WriteLine("Parse key and/or ID not found. Those are mandatory.");
|
||||||
|
Console.ReadKey();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//init parse
|
||||||
|
ParseClient.Initialize(c.ParseID, c.ParseKey);
|
||||||
|
|
||||||
OwnerID = c.OwnerID;
|
OwnerID = c.OwnerID;
|
||||||
password = c.Password;
|
password = c.Password;
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Console.WriteLine("Failed to load stuff from credentials.json, RTFM");
|
Console.WriteLine($"Failed to load stuff from credentials.json, RTFM\n{ex.Message}");
|
||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -61,22 +67,13 @@ namespace NadekoBot {
|
|||||||
//create new discord client
|
//create new discord client
|
||||||
client = new DiscordClient();
|
client = new DiscordClient();
|
||||||
|
|
||||||
|
|
||||||
//create a command service
|
//create a command service
|
||||||
var commandService = new CommandService(new CommandServiceConfig {
|
var commandService = new CommandService(new CommandServiceConfig {
|
||||||
CommandChar = null,
|
CommandChar = null,
|
||||||
HelpMode = HelpMode.Disable
|
HelpMode = HelpMode.Disable
|
||||||
});
|
});
|
||||||
|
|
||||||
//init parse
|
|
||||||
if (c.ParseKey != null && c.ParseID != null && c.ParseID != "" && c.ParseKey != "") {
|
|
||||||
ParseClient.Initialize(c.ParseID, c.ParseKey);
|
|
||||||
|
|
||||||
//monitor commands for logging
|
|
||||||
|
|
||||||
} else {
|
|
||||||
Console.WriteLine("Parse key and/or ID not found. Logging disabled.");
|
|
||||||
}
|
|
||||||
|
|
||||||
//reply to personal messages and forward if enabled.
|
//reply to personal messages and forward if enabled.
|
||||||
client.MessageReceived += Client_MessageReceived;
|
client.MessageReceived += Client_MessageReceived;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user