Decently sized C#6 refactor
Also removed unused using statements
This commit is contained in:
parent
1847ddbbe2
commit
d9657436a4
@ -58,14 +58,10 @@ public class Cards
|
|||||||
this.suit = s;
|
this.suit = s;
|
||||||
this.number = card_num;
|
this.number = card_num;
|
||||||
}
|
}
|
||||||
public string GetName() {
|
|
||||||
return cardNames[number];
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string ToString()
|
public string GetName() => cardNames[number];
|
||||||
{
|
|
||||||
return cardNames[number] + " Of " + suit;
|
public override string ToString() => cardNames[number] + " Of " + suit;
|
||||||
}
|
|
||||||
|
|
||||||
public int CompareTo(object obj)
|
public int CompareTo(object obj)
|
||||||
{
|
{
|
||||||
@ -95,11 +91,7 @@ public class Cards
|
|||||||
/// Restart the game of blackjack. It will only refill the pool for now. Probably wont be used, unless you want to have only 1 bjg running at one time,
|
/// Restart the game of blackjack. It will only refill the pool for now. Probably wont be used, unless you want to have only 1 bjg running at one time,
|
||||||
/// then you will restart the same game every time.
|
/// then you will restart the same game every time.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Restart()
|
public void Restart() => RefillPool();
|
||||||
{
|
|
||||||
// you dont have to uncover what is actually happening anda da hood
|
|
||||||
RefillPool();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Removes all cards from the pool and refills the pool with all of the possible cards. NOTE: I think this is too expensive.
|
/// Removes all cards from the pool and refills the pool with all of the possible cards. NOTE: I think this is too expensive.
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
@ -34,9 +33,7 @@ namespace NadekoBot
|
|||||||
/// <param name="message">Message to be sent</param>
|
/// <param name="message">Message to be sent</param>
|
||||||
/// <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);
|
||||||
return 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>
|
||||||
|
@ -6,8 +6,6 @@ using System.Collections.Generic;
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Http;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Timers;
|
using System.Timers;
|
||||||
|
|
||||||
@ -31,13 +29,9 @@ namespace NadekoBot
|
|||||||
return tg;
|
return tg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TriviaQuestion GetCurrentQuestion(long serverId) {
|
public TriviaQuestion GetCurrentQuestion(long serverId) => runningTrivias[serverId].currentQuestion;
|
||||||
return runningTrivias[serverId].currentQuestion;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override Func<CommandEventArgs, Task> DoFunc()
|
public override Func<CommandEventArgs, Task> DoFunc() => async e =>
|
||||||
{
|
|
||||||
return async e =>
|
|
||||||
{
|
{
|
||||||
TriviaGame tg;
|
TriviaGame tg;
|
||||||
if ((tg = StartNewGame(e)) != null)
|
if ((tg = StartNewGame(e)) != null)
|
||||||
@ -47,11 +41,8 @@ namespace NadekoBot
|
|||||||
else
|
else
|
||||||
await e.Send("Trivia game is already running on this server. The question is:\n**" + GetCurrentQuestion(e.Server.Id).Question + "**");
|
await e.Send("Trivia game is already running on this server. The question is:\n**" + GetCurrentQuestion(e.Server.Id).Question + "**");
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
private Func<CommandEventArgs, Task> LbFunc()
|
private Func<CommandEventArgs, Task> LbFunc() => async e =>
|
||||||
{
|
|
||||||
return async e =>
|
|
||||||
{
|
{
|
||||||
if (runningTrivias.ContainsKey(e.Server.Id))
|
if (runningTrivias.ContainsKey(e.Server.Id))
|
||||||
{
|
{
|
||||||
@ -61,11 +52,8 @@ namespace NadekoBot
|
|||||||
else
|
else
|
||||||
await e.Send("Trivia game is not running on this server.");
|
await e.Send("Trivia game is not running on this server.");
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
private Func<CommandEventArgs, Task> RepeatFunc()
|
private Func<CommandEventArgs, Task> RepeatFunc() => async e =>
|
||||||
{
|
|
||||||
return async e =>
|
|
||||||
{
|
{
|
||||||
if (runningTrivias.ContainsKey(e.Server.Id))
|
if (runningTrivias.ContainsKey(e.Server.Id))
|
||||||
{
|
{
|
||||||
@ -75,7 +63,6 @@ namespace NadekoBot
|
|||||||
else
|
else
|
||||||
await e.Send("Trivia game is not running on this server.");
|
await e.Send("Trivia game is not running on this server.");
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
public override void Init(CommandGroupBuilder cgb)
|
public override void Init(CommandGroupBuilder cgb)
|
||||||
{
|
{
|
||||||
@ -97,9 +84,7 @@ namespace NadekoBot
|
|||||||
.Do(QuitFunc());
|
.Do(QuitFunc());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Func<CommandEventArgs, Task> QuitFunc()
|
private Func<CommandEventArgs, Task> QuitFunc() => async e =>
|
||||||
{
|
|
||||||
return async e =>
|
|
||||||
{
|
{
|
||||||
if (runningTrivias.ContainsKey(e.Server.Id) && runningTrivias[e.Server.Id].ChannelId == e.Channel.Id)
|
if (runningTrivias.ContainsKey(e.Server.Id) && runningTrivias[e.Server.Id].ChannelId == e.Channel.Id)
|
||||||
{
|
{
|
||||||
@ -108,7 +93,6 @@ namespace NadekoBot
|
|||||||
}
|
}
|
||||||
else await e.Send("No trivias are running on this channel.");
|
else await e.Send("No trivias are running on this channel.");
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
internal static void FinishGame(TriviaGame triviaGame)
|
internal static void FinishGame(TriviaGame triviaGame)
|
||||||
{
|
{
|
||||||
@ -122,13 +106,7 @@ namespace NadekoBot
|
|||||||
private long _serverId;
|
private long _serverId;
|
||||||
private long _channellId;
|
private long _channellId;
|
||||||
|
|
||||||
public long ChannelId
|
public long ChannelId => _channellId;
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return _channellId;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Dictionary<long, int> users;
|
private Dictionary<long, int> users;
|
||||||
|
|
||||||
@ -271,19 +249,21 @@ namespace NadekoBot
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TriviaQuestion {
|
public class TriviaQuestion
|
||||||
|
{
|
||||||
public string Category;
|
public string Category;
|
||||||
public string Question;
|
public string Question;
|
||||||
public string Answer;
|
public string Answer;
|
||||||
public TriviaQuestion(string q, string a) {
|
public TriviaQuestion(string q, string a)
|
||||||
|
{
|
||||||
this.Question = q;
|
this.Question = q;
|
||||||
this.Answer = a;
|
this.Answer = a;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString() =>
|
||||||
{
|
this.Category == null ?
|
||||||
return this.Category == null ? "--------**Q**--------\nQuestion: **" + this.Question + "?**" : "--------Q--------\nCategory: " + this.Category + "\nQuestion: **"+ this.Question+ "?**";
|
"--------**Q**--------\nQuestion: **" + this.Question + "?**" :
|
||||||
}
|
"--------Q--------\nCategory: " + this.Category + "\nQuestion: **" + this.Question + "?**";
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TriviaQuestionsPool {
|
public class TriviaQuestionsPool {
|
||||||
@ -303,7 +283,8 @@ namespace NadekoBot
|
|||||||
|
|
||||||
private Random _r;
|
private Random _r;
|
||||||
|
|
||||||
public TriviaQuestionsPool() {
|
public TriviaQuestionsPool()
|
||||||
|
{
|
||||||
_r = new Random();
|
_r = new Random();
|
||||||
pool = new List<TriviaQuestion>();
|
pool = new List<TriviaQuestion>();
|
||||||
JArray arr = JArray.Parse(File.ReadAllText("questions.txt"));
|
JArray arr = JArray.Parse(File.ReadAllText("questions.txt"));
|
||||||
@ -313,7 +294,8 @@ namespace NadekoBot
|
|||||||
TriviaQuestion tq;
|
TriviaQuestion tq;
|
||||||
tq = new TriviaQuestion((string)item["Question"], (string)item["Answer"]);
|
tq = new TriviaQuestion((string)item["Question"], (string)item["Answer"]);
|
||||||
|
|
||||||
if (item?["Category"] != null) {
|
if (item?["Category"] != null)
|
||||||
|
{
|
||||||
tq.Category = item["Category"].ToString();
|
tq.Category = item["Category"].ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,16 +21,14 @@
|
|||||||
public string description;
|
public string description;
|
||||||
public string image_url_lge;
|
public string image_url_lge;
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString() =>
|
||||||
{
|
"`Title:` **" + title_english +
|
||||||
return "`Title:` **" + title_english +
|
|
||||||
"**\n`Status:` " + airing_status +
|
"**\n`Status:` " + airing_status +
|
||||||
"\n`Episodes:` " + total_episodes +
|
"\n`Episodes:` " + total_episodes +
|
||||||
"\n`Link:` http://anilist.co/anime/" + id +
|
"\n`Link:` http://anilist.co/anime/" + id +
|
||||||
"\n`Synopsis:` " + description.Substring(0, description.Length > 500 ? 500 : description.Length) + "..." +
|
"\n`Synopsis:` " + description.Substring(0, description.Length > 500 ? 500 : description.Length) + "..." +
|
||||||
"\n`img:` " + image_url_lge;
|
"\n`img:` " + image_url_lge;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
class MangaResult
|
class MangaResult
|
||||||
{
|
{
|
||||||
@ -42,9 +40,8 @@
|
|||||||
public int total_volumes;
|
public int total_volumes;
|
||||||
public string description;
|
public string description;
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString() =>
|
||||||
{
|
"`Title:` **" + title_english +
|
||||||
return "`Title:` **" + title_english +
|
|
||||||
"**\n`Status:` " + publishing_status +
|
"**\n`Status:` " + publishing_status +
|
||||||
"\n`Chapters:` " + total_chapters +
|
"\n`Chapters:` " + total_chapters +
|
||||||
"\n`Volumes:` " + total_volumes +
|
"\n`Volumes:` " + total_volumes +
|
||||||
@ -53,4 +50,3 @@
|
|||||||
"\n`img:` " + image_url_lge;
|
"\n`img:` " + image_url_lge;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
@ -1,7 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
|
|
||||||
@ -24,9 +22,7 @@ namespace NadekoBot
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Func<CommandEventArgs, Task> DoFunc()
|
public override Func<CommandEventArgs, Task> DoFunc() => async e =>
|
||||||
{
|
|
||||||
return async e =>
|
|
||||||
{
|
{
|
||||||
if (CopiedUsers.Contains(e.User.Id)) return;
|
if (CopiedUsers.Contains(e.User.Id)) return;
|
||||||
|
|
||||||
@ -34,7 +30,6 @@ namespace NadekoBot
|
|||||||
await e.Send(" I'll start copying you now.");
|
await e.Send(" I'll start copying you now.");
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
public override void Init(CommandGroupBuilder cgb)
|
public override void Init(CommandGroupBuilder cgb)
|
||||||
{
|
{
|
||||||
@ -49,9 +44,7 @@ namespace NadekoBot
|
|||||||
.Do(StopCopy());
|
.Do(StopCopy());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Func<CommandEventArgs, Task> StopCopy()
|
private Func<CommandEventArgs, Task> StopCopy() => async e =>
|
||||||
{
|
|
||||||
return async e =>
|
|
||||||
{
|
{
|
||||||
if (!CopiedUsers.Contains(e.User.Id)) return;
|
if (!CopiedUsers.Contains(e.User.Id)) return;
|
||||||
|
|
||||||
@ -61,4 +54,3 @@ namespace NadekoBot
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Discord.Modules;
|
|
||||||
using Discord;
|
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Drawing.Imaging;
|
using System.Drawing.Imaging;
|
||||||
|
|
||||||
@ -85,9 +82,7 @@ namespace NadekoBot
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private Image GetDice(int num) {
|
private Image GetDice(int num) => Image.FromFile("images/dice/" + num + ".png");
|
||||||
return Image.FromFile("images/dice/"+num+".png");
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Init(CommandGroupBuilder cgb)
|
public override void Init(CommandGroupBuilder cgb)
|
||||||
{
|
{
|
||||||
|
@ -13,8 +13,7 @@ namespace NadekoBot
|
|||||||
|
|
||||||
public DrawCommand() : base() { }
|
public DrawCommand() : base() { }
|
||||||
|
|
||||||
public override Func<CommandEventArgs,Task> DoFunc() {
|
public override Func<CommandEventArgs, Task> DoFunc() => async (e) =>
|
||||||
return async (e) =>
|
|
||||||
{
|
{
|
||||||
if (cards == null)
|
if (cards == null)
|
||||||
{
|
{
|
||||||
@ -49,15 +48,16 @@ namespace NadekoBot
|
|||||||
}
|
}
|
||||||
Bitmap bitmap = ImageHandler.MergeImages(images);
|
Bitmap bitmap = ImageHandler.MergeImages(images);
|
||||||
await client.SendFile(e.Channel, images.Count + " cards.jpg", ImageHandler.ImageToStream(bitmap, ImageFormat.Jpeg));
|
await client.SendFile(e.Channel, images.Count + " cards.jpg", ImageHandler.ImageToStream(bitmap, ImageFormat.Jpeg));
|
||||||
if (cardObjects.Count == 5) {
|
if (cardObjects.Count == 5)
|
||||||
|
{
|
||||||
await e.Send(Cards.GetHandValue(cardObjects));
|
await e.Send(Cards.GetHandValue(cardObjects));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex)
|
||||||
|
{
|
||||||
Console.WriteLine("Error drawing (a) card(s) " + ex.ToString());
|
Console.WriteLine("Error drawing (a) card(s) " + ex.ToString());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
public override void Init(CommandGroupBuilder cgb)
|
public override void Init(CommandGroupBuilder cgb)
|
||||||
{
|
{
|
||||||
|
@ -13,9 +13,8 @@ namespace NadekoBot
|
|||||||
_r = new Random();
|
_r = new Random();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Func<CommandEventArgs, Task> DoFunc()
|
public override Func<CommandEventArgs, Task> DoFunc() => async e =>
|
||||||
{
|
{
|
||||||
return async e => {
|
|
||||||
int num = _r.Next(0, 2);
|
int num = _r.Next(0, 2);
|
||||||
if (num == 1)
|
if (num == 1)
|
||||||
{
|
{
|
||||||
@ -26,7 +25,6 @@ namespace NadekoBot
|
|||||||
await client.SendFile(e.Channel, @"images/coins/tails.png");
|
await client.SendFile(e.Channel, @"images/coins/tails.png");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
public override void Init(CommandGroupBuilder cgb)
|
public override void Init(CommandGroupBuilder cgb)
|
||||||
{
|
{
|
||||||
|
@ -6,9 +6,7 @@ namespace NadekoBot
|
|||||||
{
|
{
|
||||||
class HelpCommand : DiscordCommand
|
class HelpCommand : DiscordCommand
|
||||||
{
|
{
|
||||||
public override Func<CommandEventArgs, Task> DoFunc()
|
public override Func<CommandEventArgs, Task> DoFunc() => async e =>
|
||||||
{
|
|
||||||
return async e =>
|
|
||||||
{
|
{
|
||||||
string helpstr = "Official repo: **github.com/Kwoth/NadekoBot/** \n";
|
string helpstr = "Official repo: **github.com/Kwoth/NadekoBot/** \n";
|
||||||
|
|
||||||
@ -31,7 +29,6 @@ namespace NadekoBot
|
|||||||
}
|
}
|
||||||
await client.SendMessage(e.User, helpstr);
|
await client.SendMessage(e.User, helpstr);
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
public override void Init(CommandGroupBuilder cgb)
|
public override void Init(CommandGroupBuilder cgb)
|
||||||
{
|
{
|
||||||
|
@ -8,7 +8,6 @@ using System.Timers;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Drawing.Imaging;
|
using System.Drawing.Imaging;
|
||||||
@ -29,10 +28,7 @@ namespace NadekoBot.Modules
|
|||||||
return cb;
|
return cb;
|
||||||
}
|
}
|
||||||
|
|
||||||
private CommandBuilder AliasCommand(CommandBuilder cb, string txt)
|
private CommandBuilder AliasCommand(CommandBuilder cb, string txt) => cb.Alias(new string[] { "," + txt, "-" + txt });
|
||||||
{
|
|
||||||
return cb.Alias(new string[] { "," + txt, "-" + txt });
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Install(ModuleManager manager)
|
public override void Install(ModuleManager manager)
|
||||||
{
|
{
|
||||||
@ -546,7 +542,7 @@ namespace NadekoBot.Modules
|
|||||||
invites+=invite.Url+"\n";
|
invites+=invite.Url+"\n";
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception) {
|
||||||
j++;
|
j++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -641,11 +637,6 @@ namespace NadekoBot.Modules
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Func<CommandEventArgs, Task> SayYes()
|
private Func<CommandEventArgs, Task> SayYes()
|
||||||
{
|
=> async e => await NadekoBot.client.SendMessage(e.Channel, "Yes. :)");
|
||||||
return async e =>
|
|
||||||
{
|
|
||||||
await NadekoBot.client.SendMessage(e.Channel, "Yes. :)");
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user