.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<Announcement>();
_conn.CreateTable<Request>(); _conn.CreateTable<Request>();
_conn.CreateTable<TypingArticle>(); _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() { 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);
@ -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) { if (buffer.Length > 0) {
Console.WriteLine("Prebuffering complete."); Console.WriteLine("Prebuffering complete.");
} else { } 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; 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}**"); await _channel.SendMessage($"☑️ {e.User.Mention} guessed it! The answer was: **{CurrentQuestion.Answer}**");
if (users[e.User] == WinRequirement) { if (users[e.User] == WinRequirement) {
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
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 { class CurrencyTransaction : IDataModel {
public string Reason { get; set; } public string Reason { get; set; }
public int Value { get; set; } public int Value { get; set; }
public long UserId { get; set; }
} }
} }

View File

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

View File

@ -567,6 +567,14 @@ namespace NadekoBot.Modules {
}); });
}); });
cgb.CreateCommand(".unstuck")
.Description("Clears the message queue. **OWNER ONLY**")
.Do(async e => {
if (e.User.Id != NadekoBot.OwnerID)
return;
await Task.Run(() => NadekoBot.client.MessageQueue.Clear());
});
/*cgb.CreateCommand(".voicetext") /*cgb.CreateCommand(".voicetext")
.Description("Enabled or disabled voice to text channel connection. Only people in a certain voice channel will see ") .Description("Enabled or disabled voice to text channel connection. Only people in a certain voice channel will see ")

View File

@ -1,5 +1,6 @@
using Discord.Commands; using Discord.Commands;
using Discord.Modules; using Discord.Modules;
using NadekoBot.Extensions;
using System.Linq; using System.Linq;
namespace NadekoBot.Modules namespace NadekoBot.Modules
@ -32,6 +33,31 @@ namespace NadekoBot.Modules
var members = role.Members.Where(u => u.Status == Discord.UserStatus.Online); // only online var members = role.Members.Where(u => u.Status == Discord.UserStatus.Online); // only online
await e.Channel.SendMessage($"**Raffled user:** {members.ToArray()[new System.Random().Next(0, members.Count())].Name}"); await e.Channel.SendMessage($"**Raffled user:** {members.ToArray()[new System.Random().Next(0, members.Count())].Name}");
}); });
/*
cgb.CreateCommand("$$")
.Description("Add moneyz")
.Parameter("val", ParameterType.Required)
.Do(e => {
var arg = e.GetArg("val");
var num = int.Parse(arg);
Classes.DBHandler.Instance.InsertData(
new Classes._DataModels.CurrencyTransaction {
Value = num,
Reason = "Money plz",
UserId = (long)e.User.Id,
});
});
*/
cgb.CreateCommand("$$$")
.Description("Check how many NadekoPoints you have.")
.Do(async e => {
var pts = Classes.DBHandler.Instance.GetStateByUserId((long)e.User.Id)?.Value ?? 0;
string str = $"`You have {pts} NadekoPoints".SnPl((int)pts)+"`\n";
for (int i = 0; i < pts; i++) {
str += "🌸";
}
await e.Channel.SendMessage(str);
});
}); });
} }
} }

View File

@ -48,7 +48,7 @@ namespace NadekoBot.Modules {
cgb.CreateCommand("p") cgb.CreateCommand("p")
.Alias("pause") .Alias("pause")
.Description("Pauses the song") .Description("Pauses or Unpauses the song")
.Do(async e => { .Do(async e => {
if (musicPlayers.ContainsKey(e.Server) == false) return; if (musicPlayers.ContainsKey(e.Server) == false) return;
if (musicPlayers[e.Server].TogglePause()) if (musicPlayers[e.Server].TogglePause())

View File

@ -133,8 +133,8 @@
<Compile Include="Classes\Music\SoundCloud.cs" /> <Compile Include="Classes\Music\SoundCloud.cs" />
<Compile Include="Classes\_DataModels\AnnouncementModel.cs" /> <Compile Include="Classes\_DataModels\AnnouncementModel.cs" />
<Compile Include="Classes\_DataModels\CommandModel.cs" /> <Compile Include="Classes\_DataModels\CommandModel.cs" />
<Compile Include="Classes\_DataModels\Currency.cs" /> <Compile Include="Classes\_DataModels\CurrencyStateModel.cs" />
<Compile Include="Classes\_DataModels\CurrencyTransaction.cs" /> <Compile Include="Classes\_DataModels\CurrencyTransactionModel.cs" />
<Compile Include="Classes\_DataModels\IDataModel.cs" /> <Compile Include="Classes\_DataModels\IDataModel.cs" />
<Compile Include="Classes\_DataModels\RequestModel.cs" /> <Compile Include="Classes\_DataModels\RequestModel.cs" />
<Compile Include="Classes\_DataModels\StatsModel.cs" /> <Compile Include="Classes\_DataModels\StatsModel.cs" />