More refactor, more extension methods.
Preparing to ditch this project... I just want to reimplement image searches and then i will probably stop working on this project.
This commit is contained in:
parent
5fb1a7fa31
commit
537595694a
@ -34,6 +34,7 @@ namespace NadekoBot
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static async Task<Message> Send(this CommandEventArgs e, string message)
|
public static async Task<Message> Send(this CommandEventArgs e, string message)
|
||||||
=> await NadekoBot.client.SendMessage(e.Channel, message);
|
=> await NadekoBot.client.SendMessage(e.Channel, message);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sends a message to the channel from which MessageEventArg came.
|
/// Sends a message to the channel from which MessageEventArg came.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -45,16 +46,55 @@ namespace NadekoBot
|
|||||||
await NadekoBot.client.SendMessage(e.Channel, message);
|
await NadekoBot.client.SendMessage(e.Channel, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sends a message to this channel.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="c"></param>
|
||||||
|
/// <param name="message"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static async Task Send(this Channel c, string message)
|
||||||
|
{
|
||||||
|
await NadekoBot.client.SendMessage(c, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sends a private message to this user.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="c"></param>
|
||||||
|
/// <param name="message"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static async Task Send(this User u, string message)
|
||||||
|
{
|
||||||
|
await NadekoBot.client.SendMessage(u, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Replies to a user who invoked this command, message start with that user's mention.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
/// <param name="message"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public static async Task Reply(this CommandEventArgs e, string message)
|
public static async Task Reply(this CommandEventArgs e, string message)
|
||||||
{
|
{
|
||||||
await NadekoBot.client.SendMessage(e.Channel, e.User.Mention + " " + message);
|
await e.Send(e.User.Mention + " " + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Replies to a user who invoked this command, message start with that user's mention.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
/// <param name="message"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public static async Task Reply(this MessageEventArgs e, string message)
|
public static async Task Reply(this MessageEventArgs e, string message)
|
||||||
{
|
{
|
||||||
await NadekoBot.client.SendMessage(e.Channel, e.User.Mention + " " + message);
|
await e.Send(e.User.Mention + " " + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Randomizes element order in a list
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <param name="list"></param>
|
||||||
public static void Shuffle<T>(this IList<T> list)
|
public static void Shuffle<T>(this IList<T> list)
|
||||||
{
|
{
|
||||||
RNGCryptoServiceProvider provider = new RNGCryptoServiceProvider();
|
RNGCryptoServiceProvider provider = new RNGCryptoServiceProvider();
|
||||||
|
@ -196,7 +196,7 @@ namespace NadekoBot
|
|||||||
|
|
||||||
if (currentQuestion == null || isQuit)
|
if (currentQuestion == null || isQuit)
|
||||||
{
|
{
|
||||||
client.SendMessage(ch, "Trivia bot stopping. :\\\n" + GetLeaderboard());
|
await ch.Send("Trivia bot stopping. :\\\n" + GetLeaderboard());
|
||||||
FinishGame();
|
FinishGame();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -205,7 +205,7 @@ namespace NadekoBot
|
|||||||
t.Enabled = true;
|
t.Enabled = true;
|
||||||
t.Elapsed += async (s, ev) => {
|
t.Elapsed += async (s, ev) => {
|
||||||
active = true;
|
active = true;
|
||||||
await client.SendMessage(ch, currentQuestion.ToString());
|
await ch.Send(currentQuestion.ToString());
|
||||||
t.Enabled = false;
|
t.Enabled = false;
|
||||||
timeout.Enabled = true;//starting countdown of the next question
|
timeout.Enabled = true;//starting countdown of the next question
|
||||||
stopwatch.Reset();
|
stopwatch.Reset();
|
||||||
@ -215,7 +215,7 @@ namespace NadekoBot
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async void TimeUp() {
|
private async void TimeUp() {
|
||||||
await client.SendMessage(client.GetChannel(_channellId), "**Time's up.**\nCorrect answer was: **" + currentQuestion.Answer+"**\n\n*[tq quits trivia][tl shows leaderboard]["+NadekoBot.botMention+" clr clears my messages]*");
|
await client.GetChannel(_channellId)?.Send("**Time's up.**\nCorrect answer was: **" + currentQuestion.Answer+"**\n\n*[tq quits trivia][tl shows leaderboard]["+NadekoBot.botMention+" clr clears my messages]*");
|
||||||
LoadNextRound();
|
LoadNextRound();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,10 +24,10 @@ namespace NadekoBot
|
|||||||
while (helpstr.Length > 2000)
|
while (helpstr.Length > 2000)
|
||||||
{
|
{
|
||||||
var curstr = helpstr.Substring(0, 2000);
|
var curstr = helpstr.Substring(0, 2000);
|
||||||
await client.SendMessage(e.User, curstr.Substring(0, curstr.LastIndexOf("\n") + 1));
|
await e.User.Send(curstr.Substring(0, curstr.LastIndexOf("\n") + 1));
|
||||||
helpstr = curstr.Substring(curstr.LastIndexOf("\n") + 1) + helpstr.Substring(2000);
|
helpstr = curstr.Substring(curstr.LastIndexOf("\n") + 1) + helpstr.Substring(2000);
|
||||||
}
|
}
|
||||||
await client.SendMessage(e.User, helpstr);
|
await e.User.Send(helpstr);
|
||||||
};
|
};
|
||||||
|
|
||||||
public override void Init(CommandGroupBuilder cgb)
|
public override void Init(CommandGroupBuilder cgb)
|
||||||
|
@ -351,7 +351,7 @@ namespace NadekoBot.Modules
|
|||||||
f.Read(b, 0, b.Length);
|
f.Read(b, 0, b.Length);
|
||||||
f.Close();
|
f.Close();
|
||||||
string str = Encoding.ASCII.GetString(b);
|
string str = Encoding.ASCII.GetString(b);
|
||||||
await client.SendMessage(e.User, "```" + (str.Length < 1950 ? str : str.Substring(0, 1950)) + "```");
|
await e.User.Send("```" + (str.Length < 1950 ? str : str.Substring(0, 1950)) + "```");
|
||||||
});
|
});
|
||||||
|
|
||||||
CreateCommand(cgb, "cs")
|
CreateCommand(cgb, "cs")
|
||||||
@ -400,9 +400,9 @@ namespace NadekoBot.Modules
|
|||||||
{
|
{
|
||||||
string str = StatsCollector.GetRequests();
|
string str = StatsCollector.GetRequests();
|
||||||
if (str.Trim().Length > 110)
|
if (str.Trim().Length > 110)
|
||||||
await client.SendMessage(e.User, str);
|
await e.User.Send(str);
|
||||||
else
|
else
|
||||||
await client.SendMessage(e.User, "No requests atm.");
|
await e.User.Send("No requests atm.");
|
||||||
});
|
});
|
||||||
|
|
||||||
CreateCommand(cgb, "dr")
|
CreateCommand(cgb, "dr")
|
||||||
@ -444,7 +444,7 @@ namespace NadekoBot.Modules
|
|||||||
if (sc != null)
|
if (sc != null)
|
||||||
{
|
{
|
||||||
await e.Send(e.User.Mention + " Request resolved, notice sent.");
|
await e.Send(e.User.Mention + " Request resolved, notice sent.");
|
||||||
await client.SendMessage(client.GetUser(client.GetServer(sc.ServerId), sc.Id), "**This request of yours has been resolved:**\n" + sc.Text);
|
await client.GetUser(client.GetServer(sc.ServerId), sc.Id).Send("**This request of yours has been resolved:**\n" + sc.Text);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -637,6 +637,6 @@ namespace NadekoBot.Modules
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Func<CommandEventArgs, Task> SayYes()
|
private Func<CommandEventArgs, Task> SayYes()
|
||||||
=> async e => await NadekoBot.client.SendMessage(e.Channel, "Yes. :)");
|
=> async e => await e.Send("Yes. :)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ namespace NadekoBot.Modules
|
|||||||
private static bool exit = true;
|
private static bool exit = true;
|
||||||
|
|
||||||
public static bool NextSong = false;
|
public static bool NextSong = false;
|
||||||
public static Discord.Audio.DiscordAudioClient Voice;
|
public static DiscordAudioClient Voice;
|
||||||
public static Channel VoiceChannel;
|
public static Channel VoiceChannel;
|
||||||
public static bool Pause = false;
|
public static bool Pause = false;
|
||||||
public static List<YouTubeVideo> SongQueue = new List<YouTubeVideo>();
|
public static List<YouTubeVideo> SongQueue = new List<YouTubeVideo>();
|
||||||
|
@ -36,7 +36,7 @@ namespace NadekoBot.Modules
|
|||||||
if (!(await ValidateQuery(e.Channel, e.GetArg("query")))) return;
|
if (!(await ValidateQuery(e.Channel, e.GetArg("query")))) return;
|
||||||
|
|
||||||
var str = ShortenUrl(FindYoutubeUrlByKeywords(e.GetArg("query")));
|
var str = ShortenUrl(FindYoutubeUrlByKeywords(e.GetArg("query")));
|
||||||
if (str == null || str.Trim().Length < 5)
|
if (string.IsNullOrEmpty(str.Trim()))
|
||||||
{
|
{
|
||||||
await e.Send( "Query failed");
|
await e.Send( "Query failed");
|
||||||
return;
|
return;
|
||||||
@ -140,9 +140,9 @@ namespace NadekoBot.Modules
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static async Task<bool> ValidateQuery(Discord.Channel ch,string query) {
|
private static async Task<bool> ValidateQuery(Discord.Channel ch,string query) {
|
||||||
if (query == null || query.Trim().Length == 0)
|
if (string.IsNullOrEmpty(query.Trim()))
|
||||||
{
|
{
|
||||||
await NadekoBot.client.SendMessage(ch, "Please specify search parameters.");
|
await ch.Send("Please specify search parameters.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -69,7 +69,7 @@ namespace NadekoBot
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
await NadekoBot.client.AcceptInvite(await NadekoBot.client.GetInvite(code));
|
await NadekoBot.client.AcceptInvite(await NadekoBot.client.GetInvite(code));
|
||||||
await NadekoBot.client.SendMessage(e.Channel, e.User.Mention + " I joined it, thanks :)");
|
await e.Send(e.User.Mention + " I joined it, thanks :)");
|
||||||
DEBUG_LOG("Sucessfuly joined server with code " + code);
|
DEBUG_LOG("Sucessfuly joined server with code " + code);
|
||||||
DEBUG_LOG("Here is a link for you: discord.gg/" + code);
|
DEBUG_LOG("Here is a link for you: discord.gg/" + code);
|
||||||
}
|
}
|
||||||
@ -80,7 +80,7 @@ namespace NadekoBot
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void DEBUG_LOG(string text) {
|
public static void DEBUG_LOG(string text) {
|
||||||
NadekoBot.client.SendMessage(NadekoBot.client.GetChannel(119365591852122112), text);
|
NadekoBot.client.GetChannel(119365591852122112).Send(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void StartCollecting() {
|
private void StartCollecting() {
|
||||||
|
Loading…
Reference in New Issue
Block a user