more cleanup, should build from now on - with frequent breaking changes tho.

This commit is contained in:
Master Kwoth 2016-03-02 06:00:44 +01:00
parent af5d11d533
commit d5442a4e42
26 changed files with 323 additions and 344 deletions

View File

@ -4,7 +4,7 @@ using System;
public class Cards public class Cards
{ {
private static Dictionary<int, string> cardNames = new Dictionary<int, string>() { private static readonly Dictionary<int, string> cardNames = new Dictionary<int, string>() {
{ 1, "Ace" }, { 1, "Ace" },
{ 2, "Two" }, { 2, "Two" },
{ 3, "Three" }, { 3, "Three" },
@ -17,13 +17,13 @@ public class Cards
{ 10, "Ten" }, { 10, "Ten" },
{ 11, "Jack" }, { 11, "Jack" },
{ 12, "Queen" }, { 12, "Queen" },
{ 13, "King" }, { 13, "King" }
}; };
private static Dictionary<string, Func<List<Card>, bool>> handValues; private static Dictionary<string, Func<List<Card>, bool>> handValues;
public enum CARD_SUIT public enum CardSuit
{ {
Spades = 1, Spades = 1,
Hearts = 2, Hearts = 2,
@ -33,41 +33,41 @@ public class Cards
public class Card : IComparable public class Card : IComparable
{ {
public CARD_SUIT suit; public CardSuit Suit { get; }
public int number; public int Number { get; }
public string Name public string Name
{ {
get get
{ {
string str = ""; var str = "";
if (number <= 10 && number > 1) if (Number <= 10 && Number > 1)
{ {
str += "_"+number; str += "_"+Number;
} }
else else
{ {
str += GetName().ToLower(); str += GetName().ToLower();
} }
return str + "_of_" + suit.ToString().ToLower(); return str + "_of_" + Suit.ToString().ToLower();
} }
} }
public Card(CARD_SUIT s, int card_num) { public Card(CardSuit s, int cardNum) {
this.suit = s; this.Suit = s;
this.number = card_num; this.Number = cardNum;
} }
public string GetName() => cardNames[number]; public string GetName() => cardNames[Number];
public override string ToString() => cardNames[number] + " Of " + suit; public override string ToString() => cardNames[Number] + " Of " + Suit;
public int CompareTo(object obj) public int CompareTo(object obj)
{ {
if (!(obj is Card)) return 0; if (!(obj is Card)) return 0;
var c = (Card)obj; var c = (Card)obj;
return this.number - c.number; return this.Number - c.Number;
} }
} }
@ -101,15 +101,15 @@ public class Cards
{ {
cardPool.Clear(); cardPool.Clear();
//foreach suit //foreach suit
for (int j = 1; j < 14; j++) for (var j = 1; j < 14; j++)
{ {
// and number // and number
for (int i = 1; i < 5; i++) for (var i = 1; i < 5; i++)
{ {
//generate a card of that suit and number and add it to the pool //generate a card of that suit and number and add it to the pool
// the pool will go from ace of spades,hears,diamonds,clubs all the way to the king of spades. hearts, ... // the pool will go from ace of spades,hears,diamonds,clubs all the way to the king of spades. hearts, ...
cardPool.Add(new Card((CARD_SUIT)i, j)); cardPool.Add(new Card((CardSuit)i, j));
} }
} }
} }
@ -124,8 +124,8 @@ public class Cards
Restart(); Restart();
//you can either do this if your deck is not shuffled //you can either do this if your deck is not shuffled
int num = r.Next(0, cardPool.Count); var num = r.Next(0, cardPool.Count);
Card c = cardPool[num]; var c = cardPool[num];
cardPool.RemoveAt(num); cardPool.RemoveAt(num);
return c; return c;
@ -140,44 +140,43 @@ public class Cards
/// Shuffles the deck. Use this if you want to take cards from the top of the deck, instead of randomly. See DrawACard method. /// Shuffles the deck. Use this if you want to take cards from the top of the deck, instead of randomly. See DrawACard method.
/// </summary> /// </summary>
private void Shuffle() { private void Shuffle() {
if (cardPool.Count > 1) if (cardPool.Count <= 1) return;
{ var orderedPool = cardPool.OrderBy(x => r.Next());
cardPool.OrderBy(x => r.Next()); cardPool = cardPool as List<Card> ?? orderedPool.ToList();
}
} }
public override string ToString() => string.Join("", cardPool.Select(c => c.ToString())) + Environment.NewLine; public override string ToString() => string.Join("", cardPool.Select(c => c.ToString())) + Environment.NewLine;
public void InitHandValues() { public void InitHandValues() {
Func<List<Card>, bool> hasPair = Func<List<Card>, bool> hasPair =
cards => cards.GroupBy(card => card.number) cards => cards.GroupBy(card => card.Number)
.Count(group => group.Count() == 2) == 1; .Count(group => group.Count() == 2) == 1;
Func<List<Card>, bool> isPair = Func<List<Card>, bool> isPair =
cards => cards.GroupBy(card => card.number) cards => cards.GroupBy(card => card.Number)
.Count(group => group.Count() == 3) == 0 .Count(group => group.Count() == 3) == 0
&& hasPair(cards); && hasPair(cards);
Func<List<Card>, bool> isTwoPair = Func<List<Card>, bool> isTwoPair =
cards => cards.GroupBy(card => card.number) cards => cards.GroupBy(card => card.Number)
.Count(group => group.Count() == 2) == 2; .Count(group => group.Count() == 2) == 2;
Func<List<Card>, bool> isStraight = Func<List<Card>, bool> isStraight =
cards => cards.GroupBy(card => card.number) cards => cards.GroupBy(card => card.Number)
.Count() == cards.Count() .Count() == cards.Count()
&& cards.Max(card => (int)card.number) && cards.Max(card => (int)card.Number)
- cards.Min(card => (int)card.number) == 4; - cards.Min(card => (int)card.Number) == 4;
Func<List<Card>, bool> hasThreeOfKind = Func<List<Card>, bool> hasThreeOfKind =
cards => cards.GroupBy(card => card.number) cards => cards.GroupBy(card => card.Number)
.Any(group => group.Count() == 3); .Any(group => group.Count() == 3);
Func<List<Card>, bool> isThreeOfKind = Func<List<Card>, bool> isThreeOfKind =
cards => hasThreeOfKind(cards) && !hasPair(cards); cards => hasThreeOfKind(cards) && !hasPair(cards);
Func<List<Card>, bool> isFlush = Func<List<Card>, bool> isFlush =
cards => cards.GroupBy(card => card.suit).Count() == 1; cards => cards.GroupBy(card => card.Suit).Count() == 1;
Func<List<Card>, bool> isFourOfKind = Func<List<Card>, bool> isFourOfKind =
cards => cards.GroupBy(card => card.number) cards => cards.GroupBy(card => card.Number)
.Any(group => group.Count() == 4); .Any(group => group.Count() == 4);
Func<List<Card>, bool> isFullHouse = Func<List<Card>, bool> isFullHouse =
@ -187,7 +186,7 @@ public class Cards
cards => isFlush(cards) && isStraight(cards); cards => isFlush(cards) && isStraight(cards);
Func<List<Card>, bool> isRoyalFlush = Func<List<Card>, bool> isRoyalFlush =
cards => cards.Min(card => (int)card.number) == 10 cards => cards.Min(card => card.Number) == 10
&& hasStraightFlush(cards); && hasStraightFlush(cards);
Func<List<Card>, bool> isStraightFlush = Func<List<Card>, bool> isStraightFlush =
@ -207,13 +206,9 @@ public class Cards
}; };
} }
public static string GetHandValue(List<Card> cards) public static string GetHandValue(List<Card> cards) {
{ foreach (var kvp in handValues.Where(x => x.Value(cards))) {
foreach (var KVP in handValues) return kvp.Key;
{
if (KVP.Value(cards)) {
return KVP.Key;
}
} }
return "High card "+cards.Max().GetName(); return "High card "+cards.Max().GetName();
} }

View File

@ -6,63 +6,62 @@ using System;
using System.Linq.Expressions; using System.Linq.Expressions;
namespace NadekoBot.Classes { namespace NadekoBot.Classes {
internal class DBHandler { internal class DbHandler {
private static readonly DBHandler _instance = new DBHandler(); public static DbHandler Instance { get; } = new DbHandler();
public static DBHandler Instance => _instance;
private string _filePath { get; } = "data/nadekobot.sqlite"; private string FilePath { get; } = "data/nadekobot.sqlite";
static DBHandler() { } static DbHandler() { }
public DBHandler() { public DbHandler() {
using (var _conn = new SQLiteConnection(_filePath)) { using (var conn = new SQLiteConnection(FilePath)) {
_conn.CreateTable<Stats>(); conn.CreateTable<Stats>();
_conn.CreateTable<Command>(); conn.CreateTable<Command>();
_conn.CreateTable<Announcement>(); conn.CreateTable<Announcement>();
_conn.CreateTable<Request>(); conn.CreateTable<Request>();
_conn.CreateTable<TypingArticle>(); conn.CreateTable<TypingArticle>();
_conn.CreateTable<CurrencyState>(); conn.CreateTable<CurrencyState>();
_conn.CreateTable<CurrencyTransaction>(); conn.CreateTable<CurrencyTransaction>();
_conn.CreateTable<Donator>(); conn.CreateTable<Donator>();
_conn.CreateTable<UserQuote>(); conn.CreateTable<UserQuote>();
_conn.Execute(Queries.TransactionTriggerQuery); conn.Execute(Queries.TransactionTriggerQuery);
} }
} }
internal void InsertData<T>(T o) where T : IDataModel { internal void InsertData<T>(T o) where T : IDataModel {
using (var _conn = new SQLiteConnection(_filePath)) { using (var conn = new SQLiteConnection(FilePath)) {
_conn.Insert(o, typeof(T)); conn.Insert(o, typeof(T));
} }
} }
internal void InsertMany<T>(T objects) where T : IEnumerable<IDataModel> { internal void InsertMany<T>(T objects) where T : IEnumerable<IDataModel> {
using (var _conn = new SQLiteConnection(_filePath)) { using (var conn = new SQLiteConnection(FilePath)) {
_conn.InsertAll(objects); conn.InsertAll(objects);
} }
} }
internal void UpdateData<T>(T o) where T : IDataModel { internal void UpdateData<T>(T o) where T : IDataModel {
using (var _conn = new SQLiteConnection(_filePath)) { using (var conn = new SQLiteConnection(FilePath)) {
_conn.Update(o, typeof(T)); conn.Update(o, typeof(T));
} }
} }
internal List<T> GetAllRows<T>() where T : IDataModel, new() { internal List<T> GetAllRows<T>() where T : IDataModel, new() {
using (var _conn = new SQLiteConnection(_filePath)) { using (var conn = new SQLiteConnection(FilePath)) {
return _conn.Table<T>().ToList(); return conn.Table<T>().ToList();
} }
} }
internal CurrencyState GetStateByUserId(long Id) { internal CurrencyState GetStateByUserId(long id) {
using (var _conn = new SQLiteConnection(_filePath)) { using (var conn = new SQLiteConnection(FilePath)) {
return _conn.Table<CurrencyState>().Where(x => x.UserId == Id).FirstOrDefault(); return conn.Table<CurrencyState>().Where(x => x.UserId == id).FirstOrDefault();
} }
} }
internal T Delete<T>(int Id) where T : IDataModel, new() { internal T Delete<T>(int id) where T : IDataModel, new() {
using (var _conn = new SQLiteConnection(_filePath)) { using (var conn = new SQLiteConnection(FilePath)) {
var found = _conn.Find<T>(Id); var found = conn.Find<T>(id);
if (found != null) if (found != null)
_conn.Delete<T>(found.Id); conn.Delete<T>(found.Id);
return found; return found;
} }
} }
@ -71,19 +70,19 @@ namespace NadekoBot.Classes {
/// Updates an existing object or creates a new one /// Updates an existing object or creates a new one
/// </summary> /// </summary>
internal void Save<T>(T o) where T : IDataModel, new() { internal void Save<T>(T o) where T : IDataModel, new() {
using (var _conn = new SQLiteConnection(_filePath)) { using (var conn = new SQLiteConnection(FilePath)) {
var found = _conn.Find<T>(o.Id); var found = conn.Find<T>(o.Id);
if (found == null) if (found == null)
_conn.Insert(o, typeof(T)); conn.Insert(o, typeof(T));
else else
_conn.Update(o, typeof(T)); conn.Update(o, typeof(T));
} }
} }
internal T GetRandom<T>(Expression<Func<T, bool>> p) where T : IDataModel, new() { internal T GetRandom<T>(Expression<Func<T, bool>> p) where T : IDataModel, new() {
using (var _conn = new SQLiteConnection(_filePath)) { using (var conn = new SQLiteConnection(FilePath)) {
var r = new Random(); var r = new Random();
return _conn.Table<T>().Where(p).ToList().OrderBy(x => r.Next()).FirstOrDefault(); return conn.Table<T>().Where(p).ToList().OrderBy(x => r.Next()).FirstOrDefault();
} }
} }
} }

View File

@ -15,8 +15,8 @@ namespace NadekoBot.Extensions {
public static string Scramble(this string word) { public static string Scramble(this string word) {
var letters = word.ToArray(); var letters = word.ToArray();
int count = 0; var count = 0;
for (int i = 0; i < letters.Length; i++) { for (var i = 0; i < letters.Length; i++) {
if (letters[i] == ' ') if (letters[i] == ' ')
continue; continue;
@ -34,11 +34,11 @@ namespace NadekoBot.Extensions {
} }
public static string TrimTo(this string str, int num) { public static string TrimTo(this string str, int num) {
if (num < 0) if (num < 0)
throw new ArgumentException("TrimTo argument cannot be less than 0"); throw new ArgumentOutOfRangeException(nameof(num), "TrimTo argument cannot be less than 0");
if (num == 0) if (num == 0)
return String.Empty; return string.Empty;
if (num <= 3) if (num <= 3)
return String.Join("", str.Select(c => '.')); return string.Join("", str.Select(c => '.'));
if (str.Length < num) if (str.Length < num)
return str; return str;
return string.Join("", str.Take(num - 3)) + "..."; return string.Join("", str.Take(num - 3)) + "...";
@ -131,16 +131,16 @@ namespace NadekoBot.Extensions {
/// <param name="list"></param> /// <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(); var provider = new RNGCryptoServiceProvider();
int n = list.Count; var n = list.Count;
while (n > 1) while (n > 1)
{ {
byte[] box = new byte[1]; var box = new byte[1];
do provider.GetBytes(box); do provider.GetBytes(box);
while (!(box[0] < n * (Byte.MaxValue / n))); while (!(box[0] < n * (byte.MaxValue / n)));
int k = (box[0] % n); var k = (box[0] % n);
n--; n--;
T value = list[k]; var value = list[k];
list[k] = list[n]; list[k] = list[n];
list[n] = value; list[n] = value;
} }
@ -163,16 +163,16 @@ namespace NadekoBot.Extensions {
public static string GetRuntime(this DiscordClient c) => ".Net Framework 4.5.2"; public static string GetRuntime(this DiscordClient c) => ".Net Framework 4.5.2";
public static void ForEach<T>(this IEnumerable<T> source, Action<T> action) { public static void ForEach<T>(this IEnumerable<T> source, Action<T> action) {
foreach (T element in source) { foreach (var element in source) {
action(element); action(element);
} }
} }
//http://www.dotnetperls.com/levenshtein //http://www.dotnetperls.com/levenshtein
public static int LevenshteinDistance(this string s, string t) { public static int LevenshteinDistance(this string s, string t) {
int n = s.Length; var n = s.Length;
int m = t.Length; var m = t.Length;
int[,] d = new int[n + 1, m + 1]; var d = new int[n + 1, m + 1];
// Step 1 // Step 1
if (n == 0) { if (n == 0) {
@ -184,18 +184,18 @@ namespace NadekoBot.Extensions {
} }
// Step 2 // Step 2
for (int i = 0; i <= n; d[i, 0] = i++) { for (var i = 0; i <= n; d[i, 0] = i++) {
} }
for (int j = 0; j <= m; d[0, j] = j++) { for (var j = 0; j <= m; d[0, j] = j++) {
} }
// Step 3 // Step 3
for (int i = 1; i <= n; i++) { for (var i = 1; i <= n; i++) {
//Step 4 //Step 4
for (int j = 1; j <= m; j++) { for (var j = 1; j <= m; j++) {
// Step 5 // Step 5
int cost = (t[j - 1] == s[i - 1]) ? 0 : 1; var cost = (t[j - 1] == s[i - 1]) ? 0 : 1;
// Step 6 // Step 6
d[i, j] = Math.Min( d[i, j] = Math.Min(
@ -219,7 +219,7 @@ namespace NadekoBot.Extensions {
public static Stream ToStream(this Image img, System.Drawing.Imaging.ImageFormat format = null) { public static Stream ToStream(this Image img, System.Drawing.Imaging.ImageFormat format = null) {
if (format == null) if (format == null)
format = System.Drawing.Imaging.ImageFormat.Jpeg; format = System.Drawing.Imaging.ImageFormat.Jpeg;
MemoryStream stream = new MemoryStream(); var stream = new MemoryStream();
img.Save(stream, format); img.Save(stream, format);
stream.Position = 0; stream.Position = 0;
return stream; return stream;
@ -231,16 +231,17 @@ namespace NadekoBot.Extensions {
/// <param name="images">The Images you want to merge.</param> /// <param name="images">The Images you want to merge.</param>
/// <returns>Merged bitmap</returns> /// <returns>Merged bitmap</returns>
public static Bitmap Merge(this IEnumerable<Image> images,int reverseScaleFactor = 1) { public static Bitmap Merge(this IEnumerable<Image> images,int reverseScaleFactor = 1) {
if (images.Count() == 0) return null; var imageArray = images as Image[] ?? images.ToArray();
int width = images.Sum(i => i.Width); if (!imageArray.Any()) return null;
int height = images.First().Height ; var width = imageArray.Sum(i => i.Width);
Bitmap bitmap = new Bitmap(width / reverseScaleFactor, height / reverseScaleFactor); var height = imageArray.First().Height ;
var bitmap = new Bitmap(width / reverseScaleFactor, height / reverseScaleFactor);
var r = new Random(); var r = new Random();
int offsetx = 0; var offsetx = 0;
foreach (var img in images) { foreach (var img in imageArray) {
Bitmap bm = new Bitmap(img); var bm = new Bitmap(img);
for (int w = 0; w < img.Width; w++) { for (var w = 0; w < img.Width; w++) {
for (int h = 0; h < bitmap.Height; h++) { for (var h = 0; h < bitmap.Height; h++) {
bitmap.SetPixel(w / reverseScaleFactor + offsetx, h , bm.GetPixel(w, h *reverseScaleFactor)); bitmap.SetPixel(w / reverseScaleFactor + offsetx, h , bm.GetPixel(w, h *reverseScaleFactor));
} }
} }
@ -248,10 +249,12 @@ namespace NadekoBot.Extensions {
} }
return bitmap; return bitmap;
} }
/// <summary> /// <summary>
/// Merges Images into 1 Image and returns a bitmap asynchronously. /// Merges Images into 1 Image and returns a bitmap asynchronously.
/// </summary> /// </summary>
/// <param name="images">The Images you want to merge.</param> /// <param name="images">The Images you want to merge.</param>
/// <param name="reverseScaleFactor"></param>
/// <returns>Merged bitmap</returns> /// <returns>Merged bitmap</returns>
public static async Task<Bitmap> MergeAsync(this IEnumerable<Image> images, int reverseScaleFactor = 1) => public static async Task<Bitmap> MergeAsync(this IEnumerable<Image> images, int reverseScaleFactor = 1) =>
await Task.Run(() => images.Merge(reverseScaleFactor)); await Task.Run(() => images.Merge(reverseScaleFactor));

View File

@ -6,14 +6,14 @@ namespace NadekoBot.Classes {
if (amount <= 0) if (amount <= 0)
return; return;
await Task.Run(() => { await Task.Run(() => {
DBHandler.Instance.InsertData(new _DataModels.CurrencyTransaction { DbHandler.Instance.InsertData(new _DataModels.CurrencyTransaction {
Reason = reason, Reason = reason,
UserId = (long)u.Id, UserId = (long)u.Id,
Value = amount, Value = amount,
}); });
}); });
string flows = ""; var flows = "";
for (int i = 0; i < amount; i++) { for (var i = 0; i < amount; i++) {
flows += "🌸"; flows += "🌸";
} }
await u.SendMessage("👑Congratulations!👑\nYou got: "+flows); await u.SendMessage("👑Congratulations!👑\nYou got: "+flows);

View File

@ -11,8 +11,6 @@ namespace NadekoBot {
public class NadekoStats { public class NadekoStats {
public static NadekoStats Instance { get; } = new NadekoStats(); public static NadekoStats Instance { get; } = new NadekoStats();
private readonly CommandService commandService;
public string BotVersion => $"{Assembly.GetExecutingAssembly().GetName().Name} v{Assembly.GetExecutingAssembly().GetName().Version}"; public string BotVersion => $"{Assembly.GetExecutingAssembly().GetName().Name} v{Assembly.GetExecutingAssembly().GetName().Version}";
private int _commandsRan = 0; private int _commandsRan = 0;
@ -26,7 +24,7 @@ namespace NadekoBot {
static NadekoStats() { } static NadekoStats() { }
private NadekoStats() { private NadekoStats() {
commandService = NadekoBot.Client.GetService<CommandService>(); var commandService = NadekoBot.Client.GetService<CommandService>();
statsStopwatch = new Stopwatch(); statsStopwatch = new Stopwatch();
statsStopwatch.Start(); statsStopwatch.Start();
@ -37,8 +35,9 @@ namespace NadekoBot {
ServerCount = NadekoBot.Client.Servers.Count(); ServerCount = NadekoBot.Client.Servers.Count();
var channels = NadekoBot.Client.Servers.SelectMany(s => s.AllChannels); var channels = NadekoBot.Client.Servers.SelectMany(s => s.AllChannels);
TextChannelsCount = channels.Count(c => c.Type == ChannelType.Text); var channelsArray = channels as Channel[] ?? channels.ToArray();
VoiceChannelsCount = channels.Count() - TextChannelsCount; TextChannelsCount = channelsArray.Count(c => c.Type == ChannelType.Text);
VoiceChannelsCount = channelsArray.Count() - TextChannelsCount;
NadekoBot.Client.JoinedServer += (s, e) => { NadekoBot.Client.JoinedServer += (s, e) => {
try { try {
@ -123,7 +122,7 @@ namespace NadekoBot {
.Sum(x => x.Users.Count(u => u.Status == UserStatus.Online))); .Sum(x => x.Users.Count(u => u.Status == UserStatus.Online)));
var connectedServers = NadekoBot.Client.Servers.Count(); var connectedServers = NadekoBot.Client.Servers.Count();
Classes.DBHandler.Instance.InsertData(new Classes._DataModels.Stats { Classes.DbHandler.Instance.InsertData(new Classes._DataModels.Stats {
OnlineUsers = onlineUsers, OnlineUsers = onlineUsers,
RealOnlineUsers = realOnlineUsers, RealOnlineUsers = realOnlineUsers,
Uptime = GetUptime(), Uptime = GetUptime(),
@ -141,7 +140,7 @@ namespace NadekoBot {
private void StatsCollector_RanCommand(object sender, CommandEventArgs e) { private void StatsCollector_RanCommand(object sender, CommandEventArgs e) {
try { try {
_commandsRan++; _commandsRan++;
Classes.DBHandler.Instance.InsertData(new Classes._DataModels.Command { Classes.DbHandler.Instance.InsertData(new Classes._DataModels.Command {
ServerId = (long)e.Server.Id, ServerId = (long)e.Server.Id,
ServerName = e.Server.Name, ServerName = e.Server.Name,
ChannelId = (long)e.Channel.Id, ChannelId = (long)e.Channel.Id,

View File

@ -7,8 +7,7 @@ using System.Collections.Concurrent;
namespace NadekoBot.Classes.Permissions { namespace NadekoBot.Classes.Permissions {
internal class PermissionChecker : IPermissionChecker { internal class PermissionChecker : IPermissionChecker {
public static readonly PermissionChecker _instance = new PermissionChecker(); public static PermissionChecker Instance { get; } = new PermissionChecker();
public static PermissionChecker Instance => _instance;
private ConcurrentDictionary<User, DateTime> timeBlackList { get; } = new ConcurrentDictionary<User, DateTime>(); private ConcurrentDictionary<User, DateTime> timeBlackList { get; } = new ConcurrentDictionary<User, DateTime>();

View File

@ -146,10 +146,12 @@ namespace NadekoBot.Classes {
return obj.items[0].id.playlistId.ToString(); return obj.items[0].id.playlistId.ToString();
} }
public static async Task<IEnumerable<string>> GetVideoIDs(string playlist) { public static async Task<IEnumerable<string>> GetVideoIDs(string playlist, int number = 30) {
if (string.IsNullOrWhiteSpace(NadekoBot.Creds.GoogleAPIKey)) { if (string.IsNullOrWhiteSpace(NadekoBot.Creds.GoogleAPIKey)) {
throw new ArgumentNullException(nameof(playlist)); throw new ArgumentNullException(nameof(playlist));
} }
if (number < 1 || number > 100)
throw new ArgumentOutOfRangeException();
var link = var link =
$"https://www.googleapis.com/youtube/v3/playlistItems?part=contentDetails" + $"https://www.googleapis.com/youtube/v3/playlistItems?part=contentDetails" +
$"&maxResults={30}" + $"&maxResults={30}" +

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -12,8 +13,8 @@ namespace NadekoBot.Classes.Trivia {
internal class TriviaGame { internal class TriviaGame {
private readonly object _guessLock = new object(); private readonly object _guessLock = new object();
private Server _server { get; } private Server server { get; }
private Channel _channel { get; } private Channel channel { get; }
private int QuestionDurationMiliseconds { get; } = 30000; private int QuestionDurationMiliseconds { get; } = 30000;
private int HintTimeoutMiliseconds { get; } = 6000; private int HintTimeoutMiliseconds { get; } = 6000;
@ -22,7 +23,7 @@ namespace NadekoBot.Classes.Trivia {
public TriviaQuestion CurrentQuestion { get; private set; } public TriviaQuestion CurrentQuestion { get; private set; }
public List<TriviaQuestion> oldQuestions { get; } = new List<TriviaQuestion>(); public List<TriviaQuestion> oldQuestions { get; } = new List<TriviaQuestion>();
public ConcurrentDictionary<User, int> users { get; } = new ConcurrentDictionary<User, int>(); public ConcurrentDictionary<User, int> Users { get; } = new ConcurrentDictionary<User, int>();
public bool GameActive { get; private set; } = false; public bool GameActive { get; private set; } = false;
public bool ShouldStopGame { get; private set; } public bool ShouldStopGame { get; private set; }
@ -30,9 +31,9 @@ namespace NadekoBot.Classes.Trivia {
public int WinRequirement { get; } = 10; public int WinRequirement { get; } = 10;
public TriviaGame(CommandEventArgs e) { public TriviaGame(CommandEventArgs e) {
_server = e.Server; server = e.Server;
_channel = e.Channel; channel = e.Channel;
Task.Run(() => StartGame()); Task.Run(StartGame);
} }
private async Task StartGame() { private async Task StartGame() {
@ -43,13 +44,13 @@ namespace NadekoBot.Classes.Trivia {
// load question // load question
CurrentQuestion = TriviaQuestionPool.Instance.GetRandomQuestion(oldQuestions); CurrentQuestion = TriviaQuestionPool.Instance.GetRandomQuestion(oldQuestions);
if (CurrentQuestion == null) { if (CurrentQuestion == null) {
await _channel.SendMessage($":exclamation: Failed loading a trivia question"); await channel.SendMessage($":exclamation: Failed loading a trivia question");
End().Wait(); await End();
return; return;
} }
oldQuestions.Add(CurrentQuestion); //add it to exclusion list so it doesn't show up again oldQuestions.Add(CurrentQuestion); //add it to exclusion list so it doesn't show up again
//sendquestion //sendquestion
await _channel.SendMessage($":question: **{CurrentQuestion.Question}**"); await channel.SendMessage($":question: **{CurrentQuestion.Question}**");
//receive messages //receive messages
NadekoBot.Client.MessageReceived += PotentialGuess; NadekoBot.Client.MessageReceived += PotentialGuess;
@ -60,7 +61,7 @@ namespace NadekoBot.Classes.Trivia {
try { try {
//hint //hint
await Task.Delay(HintTimeoutMiliseconds, token); await Task.Delay(HintTimeoutMiliseconds, token);
await _channel.SendMessage($":exclamation:**Hint:** {CurrentQuestion.GetHint()}"); await channel.SendMessage($":exclamation:**Hint:** {CurrentQuestion.GetHint()}");
//timeout //timeout
await Task.Delay(QuestionDurationMiliseconds - HintTimeoutMiliseconds, token); await Task.Delay(QuestionDurationMiliseconds - HintTimeoutMiliseconds, token);
@ -70,7 +71,7 @@ namespace NadekoBot.Classes.Trivia {
} }
GameActive = false; GameActive = false;
if (!triviaCancelSource.IsCancellationRequested) if (!triviaCancelSource.IsCancellationRequested)
await _channel.Send($":clock2: :question: **Time's up!** The correct answer was **{CurrentQuestion.Answer}**"); await channel.Send($":clock2: :question: **Time's up!** The correct answer was **{CurrentQuestion.Answer}**");
NadekoBot.Client.MessageReceived -= PotentialGuess; NadekoBot.Client.MessageReceived -= PotentialGuess;
// load next question if game is still running // load next question if game is still running
await Task.Delay(2000); await Task.Delay(2000);
@ -80,58 +81,53 @@ namespace NadekoBot.Classes.Trivia {
private async Task End() { private async Task End() {
ShouldStopGame = true; ShouldStopGame = true;
await _channel.SendMessage("**Trivia game ended**\n"+GetLeaderboard()); await channel.SendMessage("**Trivia game ended**\n" + GetLeaderboard());
TriviaGame throwAwayValue; TriviaGame throwAwayValue;
Commands.Trivia.runningTrivias.TryRemove(_server, out throwAwayValue); Commands.Trivia.runningTrivias.TryRemove(server, out throwAwayValue);
} }
public async Task StopGame() { public async Task StopGame() {
if (!ShouldStopGame) if (!ShouldStopGame)
await _channel.SendMessage(":exclamation: Trivia will stop after this question."); await channel.SendMessage(":exclamation: Trivia will stop after this question.");
ShouldStopGame = true; ShouldStopGame = true;
} }
private async void PotentialGuess(object sender, MessageEventArgs e) { private async void PotentialGuess(object sender, MessageEventArgs e) {
try { try {
if (e.Channel.IsPrivate) return; if (e.Channel.IsPrivate) return;
if (e.Server != _server) return; if (e.Server != server) return;
bool guess = false; var guess = false;
lock (_guessLock) { lock (_guessLock) {
if (GameActive && CurrentQuestion.IsAnswerCorrect(e.Message.Text) && !triviaCancelSource.IsCancellationRequested) { if (GameActive && CurrentQuestion.IsAnswerCorrect(e.Message.Text) && !triviaCancelSource.IsCancellationRequested) {
users.TryAdd(e.User, 0); //add if not exists Users.TryAdd(e.User, 0); //add if not exists
users[e.User]++; //add 1 point to the winner Users[e.User]++; //add 1 point to the winner
guess = true; guess = true;
} }
} }
if (guess) { if (!guess) return;
triviaCancelSource.Cancel(); triviaCancelSource.Cancel();
await _channel.SendMessage($"☑️ {e.User.Mention} guessed it! The answer was: **{CurrentQuestion.Answer}**"); await channel.SendMessage($"☑️ {e.User.Mention} guessed it! The answer was: **{CurrentQuestion.Answer}**");
if (users[e.User] == WinRequirement) { if (Users[e.User] != WinRequirement) return;
ShouldStopGame = true; ShouldStopGame = true;
await _channel.Send($":exclamation: We have a winner! Its {e.User.Mention}."); await channel.Send($":exclamation: We have a winner! Its {e.User.Mention}.");
// add points to the winner // add points to the winner
await FlowersHandler.AddFlowersAsync(e.User, "Won Trivia", 2); await FlowersHandler.AddFlowersAsync(e.User, "Won Trivia", 2);
} } catch { }
}
}
catch { }
} }
public string GetLeaderboard() { public string GetLeaderboard() {
if (users.Count == 0) if (Users.Count == 0)
return ""; return "";
string str = "**Leaderboard:**\n-----------\n"; var sb = new StringBuilder();
sb.Append("**Leaderboard:**\n-----------\n");
if (users.Count > 1) foreach (var kvp in Users.OrderBy(kvp => kvp.Value)) {
users.OrderBy(kvp => kvp.Value); sb.AppendLine($"**{kvp.Key.Name}** has {kvp.Value} points".ToString().SnPl(kvp.Value));
foreach (var kvp in users) {
str += $"**{kvp.Key.Name}** has {kvp.Value} points".ToString().SnPl(kvp.Value) + Environment.NewLine;
} }
return str; return sb.ToString();
} }
} }
} }

View File

@ -4,16 +4,16 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord.Commands; using Discord.Commands;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Linq;
using System.Threading; using System.Threading;
namespace NadekoBot.Commands { namespace NadekoBot.Commands {
internal class ClashOfClans : DiscordCommand { internal class ClashOfClans : DiscordCommand {
private const string prefix = ",";
private static string prefix = ",";
public static ConcurrentDictionary<ulong, List<ClashWar>> ClashWars { get; } = new ConcurrentDictionary<ulong, List<ClashWar>>(); public static ConcurrentDictionary<ulong, List<ClashWar>> ClashWars { get; } = new ConcurrentDictionary<ulong, List<ClashWar>>();
private object writeLock { get; } = new object(); private readonly object writeLock = new object();
public ClashOfClans() { public ClashOfClans() {
@ -28,7 +28,7 @@ namespace NadekoBot.Commands {
if (!ClashWars.TryAdd(e.Server.Id, wars)) if (!ClashWars.TryAdd(e.Server.Id, wars))
return; return;
} }
string enemyClan = e.GetArg("enemy_clan"); var enemyClan = e.GetArg("enemy_clan");
if (string.IsNullOrWhiteSpace(enemyClan)) { if (string.IsNullOrWhiteSpace(enemyClan)) {
return; return;
} }
@ -70,10 +70,10 @@ namespace NadekoBot.Commands {
} }
var war = warsInfo.Item1[warsInfo.Item2]; var war = warsInfo.Item1[warsInfo.Item2];
try { try {
war.Start(); var startTask = war.Start();
await e.Channel.SendMessage($"🔰**STARTED WAR AGAINST {war.ShortPrint()}**"); await e.Channel.SendMessage($"🔰**STARTED WAR AGAINST {war.ShortPrint()}**");
} await startTask;
catch { } catch {
await e.Channel.SendMessage($"🔰**WAR AGAINST {war.ShortPrint()} IS ALREADY STARTED**"); await e.Channel.SendMessage($"🔰**WAR AGAINST {war.ShortPrint()} IS ALREADY STARTED**");
} }
}); });
@ -96,7 +96,7 @@ namespace NadekoBot.Commands {
var sb = new StringBuilder(); var sb = new StringBuilder();
sb.AppendLine("🔰 **LIST OF ACTIVE WARS**"); sb.AppendLine("🔰 **LIST OF ACTIVE WARS**");
sb.AppendLine("**-------------------------**"); sb.AppendLine("**-------------------------**");
for (int i = 0; i < wars.Count; i++) { for (var i = 0; i < wars.Count; i++) {
sb.AppendLine($"**#{i + 1}.** `Enemy:` **{wars[i].EnemyClan}**"); sb.AppendLine($"**#{i + 1}.** `Enemy:` **{wars[i].EnemyClan}**");
sb.AppendLine($"\t\t`Size:` **{wars[i].Size} v {wars[i].Size}**"); sb.AppendLine($"\t\t`Size:` **{wars[i].Size} v {wars[i].Size}**");
sb.AppendLine("**-------------------------**"); sb.AppendLine("**-------------------------**");
@ -131,16 +131,15 @@ namespace NadekoBot.Commands {
await e.Channel.SendMessage("💢🔰 **Invalid base number.**"); await e.Channel.SendMessage("💢🔰 **Invalid base number.**");
return; return;
} }
string usr = var usr =
string.IsNullOrWhiteSpace(e.GetArg("other_name")) ? string.IsNullOrWhiteSpace(e.GetArg("other_name")) ?
e.User.Name : e.User.Name :
e.GetArg("other_name"); e.GetArg("other_name");
try { try {
var war = warsInfo.Item1[warsInfo.Item2]; var war = warsInfo.Item1[warsInfo.Item2];
await war.Call(usr, baseNum - 1); war.Call(usr, baseNum - 1);
await e.Channel.SendMessage($"🔰**{usr}** claimed a base #{baseNum} for a war against {war.ShortPrint()}"); await e.Channel.SendMessage($"🔰**{usr}** claimed a base #{baseNum} for a war against {war.ShortPrint()}");
} } catch (Exception ex) {
catch (Exception ex) {
await e.Channel.SendMessage($"💢🔰 {ex.Message}"); await e.Channel.SendMessage($"💢🔰 {ex.Message}");
} }
}); });
@ -156,7 +155,7 @@ namespace NadekoBot.Commands {
await e.Channel.SendMessage("💢🔰 **That war does not exist.**"); await e.Channel.SendMessage("💢🔰 **That war does not exist.**");
return; return;
} }
string usr = var usr =
string.IsNullOrWhiteSpace(e.GetArg("other_name")) ? string.IsNullOrWhiteSpace(e.GetArg("other_name")) ?
e.User.Name : e.User.Name :
e.GetArg("other_name"); e.GetArg("other_name");
@ -165,8 +164,7 @@ namespace NadekoBot.Commands {
try { try {
var baseNum = war.FinishClaim(usr); var baseNum = war.FinishClaim(usr);
await e.Channel.SendMessage($"❗🔰{e.User.Mention} **DESTROYED** a base #{baseNum + 1} in a war against {war.ShortPrint()}"); await e.Channel.SendMessage($"❗🔰{e.User.Mention} **DESTROYED** a base #{baseNum + 1} in a war against {war.ShortPrint()}");
} } catch (Exception ex) {
catch (Exception ex) {
await e.Channel.SendMessage($"💢🔰 {ex.Message}"); await e.Channel.SendMessage($"💢🔰 {ex.Message}");
} }
}); });
@ -183,16 +181,15 @@ namespace NadekoBot.Commands {
await e.Channel.SendMessage("💢🔰 **That war does not exist.**"); await e.Channel.SendMessage("💢🔰 **That war does not exist.**");
return; return;
} }
string usr = var usr =
string.IsNullOrWhiteSpace(e.GetArg("other_name")) ? string.IsNullOrWhiteSpace(e.GetArg("other_name")) ?
e.User.Name : e.User.Name :
e.GetArg("other_name"); e.GetArg("other_name");
try { try {
var war = warsInfo.Item1[warsInfo.Item2]; var war = warsInfo.Item1[warsInfo.Item2];
int baseNumber = war.Uncall(usr); var baseNumber = war.Uncall(usr);
await e.Channel.SendMessage($"🔰 @{usr} has **UNCLAIMED** a base #{baseNumber + 1} from a war against {war.ShortPrint()}"); await e.Channel.SendMessage($"🔰 @{usr} has **UNCLAIMED** a base #{baseNumber + 1} from a war against {war.ShortPrint()}");
} } catch (Exception ex) {
catch (Exception ex) {
await e.Channel.SendMessage($"💢🔰 {ex.Message}"); await e.Channel.SendMessage($"💢🔰 {ex.Message}");
} }
}); });
@ -236,12 +233,12 @@ namespace NadekoBot.Commands {
} }
warsInfo.Item1[warsInfo.Item2].End(); warsInfo.Item1[warsInfo.Item2].End();
int size = warsInfo.Item1[warsInfo.Item2].Size; var size = warsInfo.Item1[warsInfo.Item2].Size;
warsInfo.Item1.RemoveAt(warsInfo.Item2); warsInfo.Item1.RemoveAt(warsInfo.Item2);
}); });
} }
private Tuple<List<ClashWar>, int> GetInfo(CommandEventArgs e) { private static Tuple<List<ClashWar>, int> GetInfo(CommandEventArgs e) {
//check if there are any wars //check if there are any wars
List<ClashWar> wars = null; List<ClashWar> wars = null;
ClashWars.TryGetValue(e.Server.Id, out wars); ClashWars.TryGetValue(e.Server.Id, out wars);
@ -262,67 +259,65 @@ namespace NadekoBot.Commands {
} }
internal class Caller { internal class Caller {
private string _user; public string CallUser { get; }
public string CallUser public DateTime TimeAdded { get; private set; }
{
get { return _user; }
set { _user = value; }
}
private DateTime timeAdded;
public DateTime TimeAdded
{
get { return timeAdded; }
set { timeAdded = value; }
}
public bool BaseDestroyed { get; internal set; } public bool BaseDestroyed { get; internal set; }
public Caller(string callUser, DateTime timeAdded, bool baseDestroyed) {
CallUser = callUser;
TimeAdded = timeAdded;
BaseDestroyed = baseDestroyed;
}
public void ResetTime() {
TimeAdded = DateTime.Now;
}
public void Destroy() {
BaseDestroyed = true;
}
} }
internal class ClashWar { internal class ClashWar {
private static TimeSpan callExpire => new TimeSpan(2, 0, 0);
public static TimeSpan callExpire => new TimeSpan(2, 0, 0);
private CommandEventArgs e; private CommandEventArgs e;
private string enemyClan; public string EnemyClan { get; }
public string EnemyClan => enemyClan; public int Size { get; }
private int size;
public int Size => size; private Caller[] bases { get; }
private Caller[] bases;
private CancellationTokenSource[] baseCancelTokens; private CancellationTokenSource[] baseCancelTokens;
private CancellationTokenSource endTokenSource = new CancellationTokenSource(); private CancellationTokenSource endTokenSource { get; } = new CancellationTokenSource();
public Action<string> OnUserTimeExpired { get; set; } = null; public event Action<string> OnUserTimeExpired = delegate { };
public Action OnWarEnded { get; set; } = null; public event Action OnWarEnded = delegate { };
public bool Started { get; set; } = false; public bool Started { get; set; } = false;
public ClashWar(string enemyClan, int size, CommandEventArgs e) { public ClashWar(string enemyClan, int size, CommandEventArgs e) {
this.enemyClan = enemyClan; this.EnemyClan = enemyClan;
this.size = size; this.Size = size;
this.bases = new Caller[size]; this.bases = new Caller[size];
this.baseCancelTokens = new CancellationTokenSource[size]; this.baseCancelTokens = new CancellationTokenSource[size];
} }
internal void End() { internal void End() {
if (!endTokenSource.Token.IsCancellationRequested) { if (endTokenSource.Token.IsCancellationRequested) return;
endTokenSource.Cancel(); endTokenSource.Cancel();
if (OnWarEnded != null)
OnWarEnded(); OnWarEnded();
} }
}
internal async Task Call(string u, int baseNumber) { internal void Call(string u, int baseNumber) {
if (baseNumber < 0 || baseNumber >= bases.Length) if (baseNumber < 0 || baseNumber >= bases.Length)
throw new ArgumentException("Invalid base number"); throw new ArgumentException("Invalid base number");
if (bases[baseNumber] != null) if (bases[baseNumber] != null)
throw new ArgumentException("That base is already claimed."); throw new ArgumentException("That base is already claimed.");
for (int i = 0; i < bases.Length; i++) { for (var i = 0; i < bases.Length; i++) {
if (bases[i]?.BaseDestroyed == false && bases[i]?.CallUser == u) if (bases[i]?.BaseDestroyed == false && bases[i]?.CallUser == u)
throw new ArgumentException($"@{u} You already claimed a base #{i + 1}. You can't claim a new one."); throw new ArgumentException($"@{u} You already claimed a base #{i + 1}. You can't claim a new one.");
} }
bases[baseNumber] = new Caller { CallUser = u.Trim(), TimeAdded = DateTime.Now, BaseDestroyed = false }; bases[baseNumber] = new Caller(u.Trim(), DateTime.Now, false);
} }
internal async Task Start() { internal async Task Start() {
@ -330,37 +325,32 @@ namespace NadekoBot.Commands {
throw new InvalidOperationException(); throw new InvalidOperationException();
try { try {
Started = true; Started = true;
for (int i = 0; i < bases.Length; i++) { foreach (var b in bases.Where(b => b != null)) {
if (bases[i] != null) b.ResetTime();
bases[i].TimeAdded = DateTime.Now;
} }
Task.Run(async () => await ClearArray()); Task.Run(async () => await ClearArray()).ConfigureAwait(false);
await Task.Delay(new TimeSpan(24, 0, 0), endTokenSource.Token); await Task.Delay(new TimeSpan(24, 0, 0), endTokenSource.Token);
} } catch { } finally {
catch (Exception) { }
finally {
End(); End();
} }
} }
internal int Uncall(string user) { internal int Uncall(string user) {
user = user.Trim(); user = user.Trim();
for (int i = 0; i < bases.Length; i++) { for (var i = 0; i < bases.Length; i++) {
if (bases[i]?.CallUser == user) { if (bases[i]?.CallUser != user) continue;
bases[i] = null; bases[i] = null;
return i; return i;
} }
}
throw new InvalidOperationException("You are not participating in that war."); throw new InvalidOperationException("You are not participating in that war.");
} }
private async Task ClearArray() { private async Task ClearArray() {
while (!endTokenSource.IsCancellationRequested) { while (!endTokenSource.IsCancellationRequested) {
await Task.Delay(5000); await Task.Delay(5000);
for (int i = 0; i < bases.Length; i++) { for (var i = 0; i < bases.Length; i++) {
if (bases[i] == null) continue; if (bases[i] == null) continue;
if (!bases[i].BaseDestroyed && DateTime.Now - bases[i].TimeAdded >= callExpire) { if (!bases[i].BaseDestroyed && DateTime.Now - bases[i].TimeAdded >= callExpire) {
Console.WriteLine($"Removing user {bases[i].CallUser}"); Console.WriteLine($"Removing user {bases[i].CallUser}");
if (OnUserTimeExpired != null)
OnUserTimeExpired(bases[i].CallUser); OnUserTimeExpired(bases[i].CallUser);
bases[i] = null; bases[i] = null;
} }
@ -370,23 +360,21 @@ namespace NadekoBot.Commands {
} }
public string ShortPrint() => public string ShortPrint() =>
$"`{enemyClan}` ({size} v {size})"; $"`{EnemyClan}` ({Size} v {Size})";
public override string ToString() { public override string ToString() {
var sb = new StringBuilder(); var sb = new StringBuilder();
sb.AppendLine($"🔰**WAR AGAINST `{enemyClan}` ({size} v {size}) INFO:**"); sb.AppendLine($"🔰**WAR AGAINST `{EnemyClan}` ({Size} v {Size}) INFO:**");
if (!Started) if (!Started)
sb.AppendLine("`not started`"); sb.AppendLine("`not started`");
for (int i = 0; i < bases.Length; i++) { for (var i = 0; i < bases.Length; i++) {
if (bases[i] == null) { if (bases[i] == null) {
sb.AppendLine($"`{i + 1}.` ❌*unclaimed*"); sb.AppendLine($"`{i + 1}.` ❌*unclaimed*");
} } else {
else {
if (bases[i].BaseDestroyed) { if (bases[i].BaseDestroyed) {
sb.AppendLine($"`{i + 1}.` ✅ `{bases[i].CallUser}` ⭐ ⭐ ⭐"); sb.AppendLine($"`{i + 1}.` ✅ `{bases[i].CallUser}` ⭐ ⭐ ⭐");
} } else {
else {
var left = Started ? callExpire - (DateTime.Now - bases[i].TimeAdded) : callExpire; var left = Started ? callExpire - (DateTime.Now - bases[i].TimeAdded) : callExpire;
sb.AppendLine($"`{i + 1}.` ✅ `{bases[i].CallUser}` {left.Hours}h {left.Minutes}m {left.Seconds}s left"); sb.AppendLine($"`{i + 1}.` ✅ `{bases[i].CallUser}` {left.Hours}h {left.Minutes}m {left.Seconds}s left");
} }
@ -398,12 +386,11 @@ namespace NadekoBot.Commands {
internal int FinishClaim(string user) { internal int FinishClaim(string user) {
user = user.Trim(); user = user.Trim();
for (int i = 0; i < bases.Length; i++) { for (var i = 0; i < bases.Length; i++) {
if (bases[i]?.BaseDestroyed == false && bases[i]?.CallUser == user) { if (bases[i]?.BaseDestroyed != false || bases[i]?.CallUser != user) continue;
bases[i].BaseDestroyed = true; bases[i].BaseDestroyed = true;
return i; return i;
} }
}
throw new InvalidOperationException($"@{user} You are either not participating in that war, or you already destroyed a base."); throw new InvalidOperationException($"@{user} You are either not participating in that war, or you already destroyed a base.");
} }
} }

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord.Commands; using Discord.Commands;
namespace NadekoBot namespace NadekoBot.Commands
{ {
internal class CopyCommand : DiscordCommand internal class CopyCommand : DiscordCommand
{ {

View File

@ -1,13 +1,13 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord.Commands; using Discord.Commands;
using System.Drawing;
using System.Drawing.Imaging;
using NadekoBot.Extensions; using NadekoBot.Extensions;
namespace NadekoBot { namespace NadekoBot.Commands {
internal class DiceRollCommand : DiscordCommand { internal class DiceRollCommand : DiscordCommand {
public DiceRollCommand() { } public DiceRollCommand() { }

View File

@ -3,7 +3,7 @@ using System.Threading.Tasks;
using Discord; using Discord;
using Discord.Commands; using Discord.Commands;
namespace NadekoBot namespace NadekoBot.Commands
{ {
/// <summary> /// <summary>
/// Base DiscordCommand Class. /// Base DiscordCommand Class.

View File

@ -1,12 +1,12 @@
using System; using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Drawing;
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord.Commands; using Discord.Commands;
using System.Drawing;
using System.Collections.Generic;
using System.Collections.Concurrent;
using NadekoBot.Extensions; using NadekoBot.Extensions;
namespace NadekoBot { namespace NadekoBot.Commands {
internal class DrawCommand : DiscordCommand { internal class DrawCommand : DiscordCommand {
private static ConcurrentDictionary<Discord.Server, Cards> AllDecks = new ConcurrentDictionary<Discord.Server, Cards>(); private static ConcurrentDictionary<Discord.Server, Cards> AllDecks = new ConcurrentDictionary<Discord.Server, Cards>();

View File

@ -1,10 +1,10 @@
using System; using System;
using System.Drawing;
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord.Commands; using Discord.Commands;
using NadekoBot.Extensions; using NadekoBot.Extensions;
using System.Drawing;
namespace NadekoBot { namespace NadekoBot.Commands {
internal class FlipCoinCommand : DiscordCommand { internal class FlipCoinCommand : DiscordCommand {
private Random _r; private Random _r;

View File

@ -1,11 +1,11 @@
using System; using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord.Commands; using Discord.Commands;
using NadekoBot.Extensions; using NadekoBot.Extensions;
using System.IO;
using System.Linq;
namespace NadekoBot { namespace NadekoBot.Commands {
internal class HelpCommand : DiscordCommand { internal class HelpCommand : DiscordCommand {
public override Func<CommandEventArgs, Task> DoFunc() => async e => { public override Func<CommandEventArgs, Task> DoFunc() => async e => {
#region OldHelp #region OldHelp

View File

@ -1,13 +1,13 @@
using System; using System;
using System.Threading.Tasks;
using Discord.Commands;
using System.Linq;
using System.Collections.Generic;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using Discord; using System.Collections.Generic;
using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks;
using Discord;
using Discord.Commands;
namespace NadekoBot.Modules { namespace NadekoBot.Commands {
internal class PollCommand : DiscordCommand { internal class PollCommand : DiscordCommand {
public static ConcurrentDictionary<Server, Poll> ActivePolls = new ConcurrentDictionary<Server, Poll>(); public static ConcurrentDictionary<Server, Poll> ActivePolls = new ConcurrentDictionary<Server, Poll>();

View File

@ -6,7 +6,7 @@ using NadekoBot.Extensions;
namespace NadekoBot.Commands { namespace NadekoBot.Commands {
internal class RequestsCommand : DiscordCommand { internal class RequestsCommand : DiscordCommand {
public void SaveRequest(CommandEventArgs e, string text) { public void SaveRequest(CommandEventArgs e, string text) {
Classes.DBHandler.Instance.InsertData(new Classes._DataModels.Request { Classes.DbHandler.Instance.InsertData(new Classes._DataModels.Request {
RequestText = text, RequestText = text,
UserName = e.User.Name, UserName = e.User.Name,
UserId = (long)e.User.Id, UserId = (long)e.User.Id,
@ -17,7 +17,7 @@ namespace NadekoBot.Commands {
} }
// todo what if it's too long? // todo what if it's too long?
public string GetRequests() { public string GetRequests() {
var task = Classes.DBHandler.Instance.GetAllRows<Classes._DataModels.Request>(); var task = Classes.DbHandler.Instance.GetAllRows<Classes._DataModels.Request>();
string str = "Here are all current requests for NadekoBot:\n\n"; string str = "Here are all current requests for NadekoBot:\n\n";
foreach (var reqObj in task) { foreach (var reqObj in task) {
@ -28,14 +28,14 @@ namespace NadekoBot.Commands {
} }
public bool DeleteRequest(int requestNumber) => public bool DeleteRequest(int requestNumber) =>
Classes.DBHandler.Instance.Delete<Classes._DataModels.Request>(requestNumber) != null; Classes.DbHandler.Instance.Delete<Classes._DataModels.Request>(requestNumber) != null;
/// <summary> /// <summary>
/// Delete a request with a number and returns that request object. /// Delete a request with a number and returns that request object.
/// </summary> /// </summary>
/// <returns>RequestObject of the request. Null if none</returns> /// <returns>RequestObject of the request. Null if none</returns>
public Classes._DataModels.Request ResolveRequest(int requestNumber) => public Classes._DataModels.Request ResolveRequest(int requestNumber) =>
Classes.DBHandler.Instance.Delete<Classes._DataModels.Request>(requestNumber); Classes.DbHandler.Instance.Delete<Classes._DataModels.Request>(requestNumber);
public override Func<CommandEventArgs, Task> DoFunc() { public override Func<CommandEventArgs, Task> DoFunc() {
throw new NotImplementedException(); throw new NotImplementedException();

View File

@ -33,7 +33,7 @@ namespace NadekoBot.Commands {
NadekoBot.Client.UserJoined += UserJoined; NadekoBot.Client.UserJoined += UserJoined;
NadekoBot.Client.UserLeft += UserLeft; NadekoBot.Client.UserLeft += UserLeft;
List<Classes._DataModels.Announcement> data = Classes.DBHandler.Instance.GetAllRows<Classes._DataModels.Announcement>(); List<Classes._DataModels.Announcement> data = Classes.DbHandler.Instance.GetAllRows<Classes._DataModels.Announcement>();
if (data.Any()) if (data.Any())
foreach (var obj in data) foreach (var obj in data)
@ -168,7 +168,7 @@ namespace NadekoBot.Commands {
internal bool ToggleByePM() => ByePM = !ByePM; internal bool ToggleByePM() => ByePM = !ByePM;
private void Save() { private void Save() {
Classes.DBHandler.Instance.Save(_model); Classes.DbHandler.Instance.Save(_model);
} }
} }

View File

@ -11,7 +11,7 @@ namespace NadekoBot.Commands {
public static class SentencesProvider { public static class SentencesProvider {
internal static string GetRandomSentence() { internal static string GetRandomSentence() {
var data = Classes.DBHandler.Instance.GetAllRows<Classes._DataModels.TypingArticle>(); var data = Classes.DbHandler.Instance.GetAllRows<Classes._DataModels.TypingArticle>();
try { try {
return data.ToList()[new Random().Next(0, data.Count())].Text; return data.ToList()[new Random().Next(0, data.Count())].Text;
} catch { } catch {
@ -153,7 +153,7 @@ namespace NadekoBot.Commands {
.Do(async e => { .Do(async e => {
if (!NadekoBot.IsOwner(e.User.Id) || string.IsNullOrWhiteSpace(e.GetArg("text"))) return; if (!NadekoBot.IsOwner(e.User.Id) || string.IsNullOrWhiteSpace(e.GetArg("text"))) return;
Classes.DBHandler.Instance.InsertData(new Classes._DataModels.TypingArticle { Classes.DbHandler.Instance.InsertData(new Classes._DataModels.TypingArticle {
Text = e.GetArg("text"), Text = e.GetArg("text"),
DateAdded = DateTime.Now DateAdded = DateTime.Now
}); });

View File

@ -10,6 +10,7 @@ using System.IO;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System.Collections.Generic; using System.Collections.Generic;
using NadekoBot.Classes;
using NadekoBot.Classes.Permissions; using NadekoBot.Classes.Permissions;
using NadekoBot.Classes._DataModels; using NadekoBot.Classes._DataModels;
using Timer = System.Timers.Timer; using Timer = System.Timers.Timer;
@ -199,8 +200,10 @@ namespace NadekoBot.Modules {
.Do(async e => { .Do(async e => {
try { try {
if (e.User.ServerPermissions.KickMembers && e.Message.MentionedUsers.Any()) { if (e.User.ServerPermissions.KickMembers && e.Message.MentionedUsers.Any()) {
var usr = e.Message.MentionedUsers.First(); var usr = e.Message.MentionedUsers.FirstOrDefault();
await e.Message.MentionedUsers.First().Kick(); if (usr == null)
return;
await usr.Kick();
await e.Channel.SendMessage("Kicked user " + usr.Name + " Id: " + usr.Id); await e.Channel.SendMessage("Kicked user " + usr.Name + " Id: " + usr.Id);
} }
} catch { } catch {
@ -215,7 +218,7 @@ namespace NadekoBot.Modules {
await e.Channel.SendMessage("You do not have permission to do that."); await e.Channel.SendMessage("You do not have permission to do that.");
return; return;
} }
if (e.Message.MentionedUsers.Count() == 0) if (!e.Message.MentionedUsers.Any())
return; return;
try { try {
foreach (var u in e.Message.MentionedUsers) { foreach (var u in e.Message.MentionedUsers) {
@ -235,7 +238,7 @@ namespace NadekoBot.Modules {
await e.Channel.SendMessage("You do not have permission to do that."); await e.Channel.SendMessage("You do not have permission to do that.");
return; return;
} }
if (e.Message.MentionedUsers.Count() == 0) if (!e.Message.MentionedUsers.Any())
return; return;
try { try {
foreach (var u in e.Message.MentionedUsers) { foreach (var u in e.Message.MentionedUsers) {
@ -256,7 +259,7 @@ namespace NadekoBot.Modules {
await e.Channel.SendMessage("You do not have permission to do that."); await e.Channel.SendMessage("You do not have permission to do that.");
return; return;
} }
if (e.Message.MentionedUsers.Count() == 0) if (!e.Message.MentionedUsers.Any())
return; return;
try { try {
foreach (var u in e.Message.MentionedUsers) { foreach (var u in e.Message.MentionedUsers) {
@ -277,7 +280,7 @@ namespace NadekoBot.Modules {
await e.Channel.SendMessage("You do not have permission to do that."); await e.Channel.SendMessage("You do not have permission to do that.");
return; return;
} }
if (e.Message.MentionedUsers.Count() == 0) if (!e.Message.MentionedUsers.Any())
return; return;
try { try {
foreach (var u in e.Message.MentionedUsers) { foreach (var u in e.Message.MentionedUsers) {
@ -323,7 +326,9 @@ namespace NadekoBot.Modules {
.Do(async e => { .Do(async e => {
try { try {
if (e.User.ServerPermissions.ManageChannels) { if (e.User.ServerPermissions.ManageChannels) {
await e.Server.FindChannels(e.GetArg("channel_name"), ChannelType.Text).FirstOrDefault()?.Delete(); var channel = e.Server.FindChannels(e.GetArg("channel_name"), ChannelType.Text).FirstOrDefault();
if (channel == null) return;
await channel.Delete();
await e.Channel.SendMessage($"Removed text channel **{e.GetArg("channel_name")}**."); await e.Channel.SendMessage($"Removed text channel **{e.GetArg("channel_name")}**.");
} }
} catch { } catch {
@ -413,15 +418,12 @@ namespace NadekoBot.Modules {
.Description("Works only for the owner. Shuts the bot down and notifies users about the restart.") .Description("Works only for the owner. Shuts the bot down and notifies users about the restart.")
.Do(async e => { .Do(async e => {
if (NadekoBot.IsOwner(e.User.Id)) { if (NadekoBot.IsOwner(e.User.Id)) {
Timer t = new Timer();
t.Interval = 2000;
t.Elapsed += (s, ev) => { Environment.Exit(0); };
t.Start();
await e.Channel.SendMessage("`Shutting down.`"); await e.Channel.SendMessage("`Shutting down.`");
await Task.Delay(2000);
Environment.Exit(0);
} }
}); });
ConcurrentDictionary<Server, bool> clearDictionary = new ConcurrentDictionary<Server, bool>();
cgb.CreateCommand(".clr") cgb.CreateCommand(".clr")
.Description("Clears some of Nadeko's (or some other user's if supplied) messages from the current channel.\n**Usage**: .clr @X") .Description("Clears some of Nadeko's (or some other user's if supplied) messages from the current channel.\n**Usage**: .clr @X")
.Parameter("user", ParameterType.Unparsed) .Parameter("user", ParameterType.Unparsed)
@ -462,18 +464,13 @@ namespace NadekoBot.Modules {
if (!NadekoBot.IsOwner(e.User.Id) || string.IsNullOrWhiteSpace(e.GetArg("img"))) if (!NadekoBot.IsOwner(e.User.Id) || string.IsNullOrWhiteSpace(e.GetArg("img")))
return; return;
// Gather user provided URL. // Gather user provided URL.
string avatarAddress = e.GetArg("img"); var avatarAddress = e.GetArg("img");
// Creates an HTTPWebRequest object, which references the URL given by the user. var imageStream = await SearchHelper.GetResponseStreamAsync(avatarAddress);
System.Net.HttpWebRequest webRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(Uri.EscapeUriString(avatarAddress)); var image = System.Drawing.Image.FromStream(imageStream);
// Discard the response if image isnt downloaded in 5 s as to not lock Nadeko. Prevents loading from faulty links.
webRequest.Timeout = 5000;
// Gathers the webRequest response as a Stream object.
System.Net.WebResponse webResponse = await webRequest.GetResponseAsync();
// Create image object from the response we got from the webRequest stream. This is because there is no "GetResponseStream".
System.Drawing.Image image = System.Drawing.Image.FromStream(webResponse.GetResponseStream());
// Save the image to disk. // Save the image to disk.
image.Save("data/avatar.png", System.Drawing.Imaging.ImageFormat.Png); image.Save("data/avatar.png", System.Drawing.Imaging.ImageFormat.Png);
await client.CurrentUser.Edit(NadekoBot.Creds.Password, avatar: image.ToStream()); imageStream.Position = 0;
await client.CurrentUser.Edit(NadekoBot.Creds.Password, avatar: imageStream);
// Send confirm. // Send confirm.
await e.Channel.SendMessage("New avatar set."); await e.Channel.SendMessage("New avatar set.");
}); });
@ -490,8 +487,8 @@ namespace NadekoBot.Modules {
cgb.CreateCommand(".checkmyperms") cgb.CreateCommand(".checkmyperms")
.Description("Checks your userspecific permissions on this channel.") .Description("Checks your userspecific permissions on this channel.")
.Do(async e => { .Do(async e => {
string output = "```\n"; var output = "```\n";
foreach (var p in e.User.ServerPermissions.GetType().GetProperties().Where(p => p.GetGetMethod().GetParameters().Count() == 0)) { foreach (var p in e.User.ServerPermissions.GetType().GetProperties().Where(p => !p.GetGetMethod().GetParameters().Any())) {
output += p.Name + ": " + p.GetValue(e.User.ServerPermissions, null).ToString() + "\n"; output += p.Name + ": " + p.GetValue(e.User.ServerPermissions, null).ToString() + "\n";
} }
output += "```"; output += "```";
@ -558,11 +555,11 @@ namespace NadekoBot.Modules {
.Description("Mentions every person from the provided role or roles (separated by a ',') on this server. Requires you to have mention everyone permission.") .Description("Mentions every person from the provided role or roles (separated by a ',') on this server. Requires you to have mention everyone permission.")
.Parameter("roles", ParameterType.Unparsed) .Parameter("roles", ParameterType.Unparsed)
.Do(async e => { .Do(async e => {
await Task.Run(async () => {
if (!e.User.ServerPermissions.MentionEveryone) return; if (!e.User.ServerPermissions.MentionEveryone) return;
var arg = e.GetArg("roles").Split(',').Select(r => r.Trim()); var arg = e.GetArg("roles").Split(',').Select(r => r.Trim());
string send = $"--{e.User.Mention} has invoked a mention on the following roles--"; string send = $"--{e.User.Mention} has invoked a mention on the following roles--";
foreach (var roleStr in arg) { foreach (var roleStr in arg.Where(str => !string.IsNullOrWhiteSpace(str))) {
if (string.IsNullOrWhiteSpace(roleStr)) continue;
var role = e.Server.FindRoles(roleStr).FirstOrDefault(); var role = e.Server.FindRoles(roleStr).FirstOrDefault();
if (role == null) continue; if (role == null) continue;
send += $"\n`{role.Name}`\n"; send += $"\n`{role.Name}`\n";
@ -571,11 +568,15 @@ namespace NadekoBot.Modules {
while (send.Length > 2000) { while (send.Length > 2000) {
var curstr = send.Substring(0, 2000); var curstr = send.Substring(0, 2000);
await e.Channel.Send(curstr.Substring(0, curstr.LastIndexOf(", ") + 1)); await
send = curstr.Substring(curstr.LastIndexOf(", ") + 1) + send.Substring(2000); e.Channel.Send(curstr.Substring(0,
curstr.LastIndexOf(", ", StringComparison.Ordinal) + 1));
send = curstr.Substring(curstr.LastIndexOf(", ", StringComparison.Ordinal) + 1) +
send.Substring(2000);
} }
await e.Channel.Send(send); await e.Channel.Send(send);
}); });
});
cgb.CreateCommand(".parsetosql") cgb.CreateCommand(".parsetosql")
.Description("Loads exported parsedata from /data/parsedata/ into sqlite database.") .Description("Loads exported parsedata from /data/parsedata/ into sqlite database.")
@ -593,7 +594,7 @@ namespace NadekoBot.Modules {
cgb.CreateCommand(".unstuck") cgb.CreateCommand(".unstuck")
.Description("Clears the message queue. **OWNER ONLY**") .Description("Clears the message queue. **OWNER ONLY**")
.AddCheck(Classes.Permissions.SimpleCheckers.OwnerOnly()) .AddCheck(SimpleCheckers.OwnerOnly())
.Do(e => { .Do(e => {
NadekoBot.Client.MessageQueue.Clear(); NadekoBot.Client.MessageQueue.Clear();
}); });
@ -602,7 +603,7 @@ namespace NadekoBot.Modules {
.Description("List of lovely people who donated to keep this project alive.") .Description("List of lovely people who donated to keep this project alive.")
.Do(async e => { .Do(async e => {
await Task.Run(async () => { await Task.Run(async () => {
var rows = Classes.DBHandler.Instance.GetAllRows<Donator>(); var rows = Classes.DbHandler.Instance.GetAllRows<Donator>();
var donatorsOrdered = rows.OrderByDescending(d => d.Amount); var donatorsOrdered = rows.OrderByDescending(d => d.Amount);
string str = $"**Thanks to the people listed below for making this project happen!**\n"; string str = $"**Thanks to the people listed below for making this project happen!**\n";
@ -616,22 +617,22 @@ namespace NadekoBot.Modules {
.Description("Add a donator to the database.") .Description("Add a donator to the database.")
.Parameter("donator") .Parameter("donator")
.Parameter("amount") .Parameter("amount")
.Do(e => { .Do(async e => {
try { await Task.Run(() => {
if (!NadekoBot.IsOwner(e.User.Id)) if (!NadekoBot.IsOwner(e.User.Id))
return; return;
var donator = e.Server.FindUsers(e.GetArg("donator")).FirstOrDefault(); var donator = e.Server.FindUsers(e.GetArg("donator")).FirstOrDefault();
var amount = int.Parse(e.GetArg("amount")); var amount = int.Parse(e.GetArg("amount"));
Classes.DBHandler.Instance.InsertData(new Donator { if (donator == null) return;
try {
Classes.DbHandler.Instance.InsertData(new Donator {
Amount = amount, Amount = amount,
UserName = donator.Name, UserName = donator.Name,
UserId = (long)e.User.Id UserId = (long)e.User.Id
}); });
e.Channel.SendMessage("Successfuly added a new donator. 👑"); e.Channel.SendMessage("Successfuly added a new donator. 👑");
} catch (Exception ex) { } catch { }
Console.WriteLine(ex); });
Console.WriteLine("---------------\nInner error:\n" + ex.InnerException);
}
}); });
cgb.CreateCommand(".videocall") cgb.CreateCommand(".videocall")
@ -639,13 +640,11 @@ namespace NadekoBot.Modules {
.Parameter("arg", ParameterType.Unparsed) .Parameter("arg", ParameterType.Unparsed)
.Do(async e => { .Do(async e => {
try { try {
string str = "http://appear.in/";
var allUsrs = e.Message.MentionedUsers.Union(new User[] { e.User }); var allUsrs = e.Message.MentionedUsers.Union(new User[] { e.User });
foreach (var usr in allUsrs) { var allUsrsArray = allUsrs as User[] ?? allUsrs.ToArray();
str += Uri.EscapeUriString(usr.Name[0].ToString()); var str = allUsrsArray.Aggregate("http://appear.in/", (current, usr) => current + Uri.EscapeUriString(usr.Name[0].ToString()));
} str += new Random().Next();
str += new Random().Next(100000, 1000000); foreach (var usr in allUsrsArray) {
foreach (var usr in allUsrs) {
await usr.SendMessage(str); await usr.SendMessage(str);
} }
} catch (Exception ex) { } catch (Exception ex) {
@ -659,11 +658,10 @@ namespace NadekoBot.Modules {
try { try {
var data = File.ReadAllText(where); var data = File.ReadAllText(where);
var arr = JObject.Parse(data)["results"] as JArray; var arr = JObject.Parse(data)["results"] as JArray;
var objects = new List<T>(); if (arr == null)
foreach (JObject obj in arr) { return;
objects.Add(obj.ToObject<T>()); var objects = arr.Select(x => x.ToObject<T>());
} Classes.DbHandler.Instance.InsertMany(objects);
Classes.DBHandler.Instance.InsertMany(objects);
} catch { } } catch { }
} }
} }

View File

@ -45,7 +45,7 @@ namespace NadekoBot.Modules {
if (string.IsNullOrWhiteSpace(text)) if (string.IsNullOrWhiteSpace(text))
return; return;
await Task.Run(() => await Task.Run(() =>
Classes.DBHandler.Instance.InsertData(new Classes._DataModels.UserQuote() { Classes.DbHandler.Instance.InsertData(new Classes._DataModels.UserQuote() {
DateAdded = DateTime.Now, DateAdded = DateTime.Now,
Keyword = e.GetArg("keyword").ToLowerInvariant(), Keyword = e.GetArg("keyword").ToLowerInvariant(),
Text = text, Text = text,
@ -64,7 +64,7 @@ namespace NadekoBot.Modules {
return; return;
var quote = var quote =
Classes.DBHandler.Instance.GetRandom<Classes._DataModels.UserQuote>( Classes.DbHandler.Instance.GetRandom<Classes._DataModels.UserQuote>(
uqm => uqm.Keyword == keyword); uqm => uqm.Keyword == keyword);
if (quote != null) if (quote != null)

View File

@ -1,5 +1,6 @@
using Discord.Modules; using Discord.Modules;
using System.Collections.Generic; using System.Collections.Generic;
using NadekoBot.Commands;
namespace NadekoBot.Modules { namespace NadekoBot.Modules {
internal abstract class DiscordModule : IModule { internal abstract class DiscordModule : IModule {

View File

@ -3,6 +3,7 @@ using Discord.Modules;
using NadekoBot.Extensions; using NadekoBot.Extensions;
using System.Linq; using System.Linq;
using Discord; using Discord;
using NadekoBot.Commands;
namespace NadekoBot.Modules namespace NadekoBot.Modules
{ {
@ -41,7 +42,7 @@ namespace NadekoBot.Modules
cgb.CreateCommand("$$$") cgb.CreateCommand("$$$")
.Description("Check how many NadekoFlowers you have.") .Description("Check how many NadekoFlowers you have.")
.Do(async e => { .Do(async e => {
var pts = Classes.DBHandler.Instance.GetStateByUserId((long)e.User.Id)?.Value ?? 0; var pts = Classes.DbHandler.Instance.GetStateByUserId((long)e.User.Id)?.Value ?? 0;
var str = $"`You have {pts} NadekoFlowers".SnPl((int)pts)+"`\n"; var str = $"`You have {pts} NadekoFlowers".SnPl((int)pts)+"`\n";
for (var i = 0; i < pts; i++) { for (var i = 0; i < pts; i++) {
str += "🌸"; str += "🌸";

View File

@ -1,6 +1,7 @@
using System.Linq; using System.Linq;
using Discord.Modules; using Discord.Modules;
using Discord.Commands; using Discord.Commands;
using NadekoBot.Commands;
namespace NadekoBot.Modules { namespace NadekoBot.Modules {
internal class Help : DiscordModule { internal class Help : DiscordModule {

View File

@ -11,6 +11,7 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using NadekoBot.Classes; using NadekoBot.Classes;
using NadekoBot.Classes.JSONModels; using NadekoBot.Classes.JSONModels;
using NadekoBot.Commands;
namespace NadekoBot { namespace NadekoBot {
public class NadekoBot { public class NadekoBot {

View File

@ -226,9 +226,6 @@
<ItemGroup> <ItemGroup>
<None Include="resources\images\hidden.png" /> <None Include="resources\images\hidden.png" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="resources\images\nadeko.jpg" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="resources\images\rip.png" /> <None Include="resources\images\rip.png" />
</ItemGroup> </ItemGroup>