.unstuck, added points, clearer descriptions, $$$ command

This commit is contained in:
Master Kwoth
2016-02-09 23:12:54 +01:00
parent a270f3c91a
commit 9f9ef8923b
11 changed files with 80 additions and 12 deletions

View File

@@ -18,6 +18,9 @@ namespace NadekoBot.Classes {
_conn.CreateTable<Announcement>();
_conn.CreateTable<Request>();
_conn.CreateTable<TypingArticle>();
_conn.CreateTable<CurrencyState>();
_conn.CreateTable<CurrencyTransaction>();
_conn.Execute(Queries.TransactionTriggerQuery);
}
}
@@ -45,6 +48,12 @@ namespace NadekoBot.Classes {
}
}
internal CurrencyState GetStateByUserId(long Id) {
using (var _conn = new SQLiteConnection(_filePath)) {
return _conn.Table<CurrencyState>().Where(x => x.UserId == Id).FirstOrDefault();
}
}
internal T Delete<T>(int Id) where T : IDataModel, new() {
using (var _conn = new SQLiteConnection(_filePath)) {
var found = _conn.Find<T>(Id);
@@ -68,3 +77,17 @@ namespace NadekoBot.Classes {
}
}
}
public static class Queries {
public static string TransactionTriggerQuery = @"
CREATE TRIGGER IF NOT EXISTS OnTransactionAdded
AFTER INSERT ON CurrencyTransaction
BEGIN
INSERT OR REPLACE INTO CurrencyState (Id, UserId, Value, DateAdded)
VALUES (COALESCE((SELECT Id from CurrencyState where UserId = NEW.UserId),(SELECT COALESCE(MAX(Id),0)+1 from CurrencyState)),
NEW.UserId,
COALESCE((SELECT Value+New.Value FROM CurrencyState Where UserId = NEW.UserId),NEW.Value),
NEW.DateAdded);
END
";
}

View File

@@ -260,7 +260,7 @@ namespace NadekoBot.Classes.Music {
if (buffer.Length > 0) {
Console.WriteLine("Prebuffering complete.");
} else {
Console.WriteLine("Didn't buffer jack shit.");
Console.WriteLine("Nothing was buffered, try another song and check your GoogleApikey.");
}
int blockSize = 1920 * NadekoBot.client.Audio().Config.Channels;

View File

@@ -110,7 +110,16 @@ namespace NadekoBot.Classes.Trivia {
await _channel.SendMessage($"☑️ {e.User.Mention} guessed it! The answer was: **{CurrentQuestion.Answer}**");
if (users[e.User] == WinRequirement) {
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
await Task.Run(async () => {
DBHandler.Instance.InsertData(new _DataModels.CurrencyTransaction {
Reason = "Won Trivia",
UserId = (long)e.User.Id,
Value = 2,
});
await e.User.SendMessage("👑Congratulations!👑\nYou got: 🌸🌸");
});
}
}
}

View File

@@ -1,6 +0,0 @@
namespace NadekoBot.Classes._DataModels {
class Currency : IDataModel {
public long UserId { get; set; }
public long Value { get; set; }
}
}

View File

@@ -0,0 +1,7 @@
namespace NadekoBot.Classes._DataModels {
class CurrencyState : IDataModel {
public long Value { get; set; }
[SQLite.Unique]
public long UserId { get; set; }
}
}

View File

@@ -2,5 +2,6 @@
class CurrencyTransaction : IDataModel {
public string Reason { get; set; }
public int Value { get; set; }
public long UserId { get; set; }
}
}

View File

@@ -2,7 +2,7 @@
using System;
namespace NadekoBot.Classes._DataModels {
class IDataModel {
abstract class IDataModel {
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
[Newtonsoft.Json.JsonProperty("createdAt")]