Added points system
This commit is contained in:
parent
c556edccff
commit
01e46f873f
@ -112,7 +112,7 @@ namespace ChaosBot.Database
|
||||
|
||||
SqliteCommand cmd = _conn.CreateCommand();
|
||||
StringBuilder commandText = new StringBuilder();
|
||||
commandText.Append("UPDATE OR FAIL ");
|
||||
commandText.Append("UPDATE ");
|
||||
commandText.Append(table);
|
||||
commandText.Append(" SET ");
|
||||
|
||||
@ -135,11 +135,11 @@ namespace ChaosBot.Database
|
||||
if (filterList.Count > 0)
|
||||
{
|
||||
commandText.Append("WHERE ");
|
||||
commandText.Append(string.Join(", ", filterList));
|
||||
commandText.Append(string.Join("AND ", filterList));
|
||||
}
|
||||
|
||||
cmd.CommandText = commandText.ToString();
|
||||
|
||||
Console.WriteLine(commandText.ToString());
|
||||
cmd.Prepare();
|
||||
cmd.ExecuteNonQuery();
|
||||
|
||||
|
||||
@ -19,7 +19,7 @@ namespace ChaosBot.Database.Repository
|
||||
List<Points> pointslist = new List<Points>();
|
||||
foreach (DataRow row in dataTable.Rows)
|
||||
{
|
||||
int id = Convert.ToInt32((long) row["id"]);
|
||||
int id = Convert.ToInt32((long)row["id"]);
|
||||
int points = Convert.ToInt32(row["points"]);
|
||||
string userId = row["userId"].ToString();
|
||||
string guildId = row["guildId"].ToString();
|
||||
@ -40,12 +40,12 @@ namespace ChaosBot.Database.Repository
|
||||
List<Points> pointslist = new List<Points>();
|
||||
foreach (DataRow row in dataTable.Rows)
|
||||
{
|
||||
int idFetch = Convert.ToInt32((long) row["id"]);
|
||||
int idFetch = Convert.ToInt32((long)row["id"]);
|
||||
int pointsFetch = Convert.ToInt32(row["points"]);
|
||||
string userIdFetch = row["userId"].ToString();
|
||||
string guildIdFetch = row["guildId"].ToString();
|
||||
|
||||
pointslist.Add(new Points(idFetch, userIdFetch, guildIdFetch ,pointsFetch));
|
||||
pointslist.Add(new Points(idFetch, userIdFetch, guildIdFetch, pointsFetch));
|
||||
}
|
||||
|
||||
return pointslist.ToArray();
|
||||
@ -82,37 +82,53 @@ namespace ChaosBot.Database.Repository
|
||||
|
||||
|
||||
|
||||
public static int Add(int userId, int points, int guildId)
|
||||
public static int Add(string userId, int points, string guildId)
|
||||
{
|
||||
Dictionary<string, object> selectfilterDict = new Dictionary<string, object>();
|
||||
selectfilterDict.Add("userId", userId);
|
||||
selectfilterDict.Add("guildId", guildId);
|
||||
DataTable dt = Controller.SelectQuery(Table, "points", selectfilterDict);
|
||||
if (Convert.ToInt32(dt.Rows.Count) != 0)
|
||||
{
|
||||
Dictionary<string, object> filterDict = new Dictionary<string, object>();
|
||||
filterDict.Add("userId", userId);
|
||||
filterDict.Add("guildId", guildId);
|
||||
|
||||
int curPoints = Convert.ToInt32(Controller.SelectQuery(Table, "points", selectfilterDict).Rows[0]["points"]);
|
||||
Dictionary<string, object> updateDict = new Dictionary<string, object>();
|
||||
updateDict.Add("points", Convert.ToInt32(dt.Rows[0]["points"]) + points);
|
||||
Controller.UpdateQuery(Table, updateDict, filterDict);
|
||||
return Convert.ToInt32(dt.Rows[0]["points"]) + points;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Dictionary<string, object> dict = new Dictionary<string, object>();
|
||||
dict.Add("userId", userId);
|
||||
dict.Add("guildId", guildId);
|
||||
dict.Add("points", points);
|
||||
|
||||
Console.WriteLine($"{curPoints}");
|
||||
|
||||
Controller.InsertQuery(Table, dict);
|
||||
return points;
|
||||
}
|
||||
}
|
||||
|
||||
public static int Remove(string userId, int points, string guildId)
|
||||
{
|
||||
Dictionary<string, object> selectfilterDict = new Dictionary<string, object>();
|
||||
selectfilterDict.Add("userId", userId);
|
||||
selectfilterDict.Add("guildId", guildId);
|
||||
DataTable dt = Controller.SelectQuery(Table, "points", selectfilterDict);
|
||||
|
||||
Dictionary<string, object> filterDict = new Dictionary<string, object>();
|
||||
filterDict.Add("userId", userId);
|
||||
filterDict.Add("guildId", guildId);
|
||||
|
||||
Dictionary<string, object> updateDict = new Dictionary<string, object>();
|
||||
// updateDict.Add("points", Convert.ToInt32(dataTable.Rows[0]["points"]) + points);
|
||||
return 0;
|
||||
//Controller.UpdateQuery(Table, updateDict, filterDict);
|
||||
//return Convert.ToInt32(dataTable.Rows[0]["points"]) + points;
|
||||
}
|
||||
updateDict.Add("points", Convert.ToInt32(dt.Rows[0]["points"]) - points);
|
||||
Controller.UpdateQuery(Table, updateDict, filterDict);
|
||||
return Convert.ToInt32(dt.Rows[0]["points"]) - points;
|
||||
|
||||
public static void ClearPoints(string guildId)
|
||||
{
|
||||
Dictionary<string,object> filterDict = new Dictionary<string, object>();
|
||||
|
||||
filterDict.Add("guildId", guildId);
|
||||
|
||||
Controller.DeleteQuery(Table, filterDict);
|
||||
}
|
||||
|
||||
public static void Delete(int userId)
|
||||
@ -123,24 +139,5 @@ namespace ChaosBot.Database.Repository
|
||||
Controller.DeleteQuery(Table, filterDict);
|
||||
}
|
||||
|
||||
public static int Remove(int userId, int points, int guildId )
|
||||
{
|
||||
Dictionary<string, object> selectfilterDict = new Dictionary<string, object>();
|
||||
selectfilterDict.Add("userId", userId);
|
||||
selectfilterDict.Add("guildId", guildId);
|
||||
|
||||
DataTable dataTable = Controller.SelectQuery(Table, "points", selectfilterDict);
|
||||
|
||||
Dictionary<string, object> filterDict = new Dictionary<string, object>();
|
||||
filterDict.Add("userId", userId);
|
||||
filterDict.Add("guildId", guildId);
|
||||
|
||||
Dictionary<string, object> updateDict = new Dictionary<string, object>();
|
||||
updateDict.Add("points", Convert.ToInt32(dataTable.Rows[0]["points"]) - points);
|
||||
|
||||
// Controller.UpdateQuery(Table, updateDict, filterDict);
|
||||
return Convert.ToInt32(dataTable.Rows[0]["points"]) - points;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -61,24 +61,33 @@ namespace ChaosBot.Discord.Modules
|
||||
|
||||
}
|
||||
|
||||
/*[Command("points add")]
|
||||
[RequireUserPermission(GuildPermission.ManageGuild)]
|
||||
[Command("points add")]
|
||||
[RequireUserPermission(ChannelPermission.ManageMessages)]
|
||||
public async Task RaffleCommandAdd(string user, int amount = 1)
|
||||
{
|
||||
if (Program.Cfg.GetValue<int>($"Servers:{Context.Guild.Id}:Raffle:Max") >= amount)
|
||||
// await RaffleCommandHelper("add", user, amount);
|
||||
|
||||
if (ChannelPermissions.Text.ManageMessages)
|
||||
{
|
||||
ulong userId = Convert.ToUInt64(user.Substring(3, user.Length - 4));
|
||||
|
||||
await ReplyAsync($"{Context.User.Mention} has given <@{userId}> {amount} points for a total of {PointsRepository.Add(userId.ToString(), amount, Context.Guild.Id.ToString())} points.", false);
|
||||
}
|
||||
else
|
||||
{
|
||||
await ReplyAsync(
|
||||
$"You cannot give more then {Program.Cfg.GetValue<int>($"Servers:{Context.Guild.Id}:Raffle:Max").ToString()} tickets at a time", false);
|
||||
_logger.Warn($"{Context.User.Username} attempted to give {amount} tickets to {user}!");
|
||||
}
|
||||
await ReplyAsync($"NO ACCESS");
|
||||
|
||||
|
||||
}
|
||||
|
||||
[Command("points remove")]
|
||||
[RequireUserPermission(GuildPermission.ManageGuild)]
|
||||
public async Task RaffleCommandClear()
|
||||
[RequireUserPermission(ChannelPermission.ManageMessages)]
|
||||
public async Task RaffleCommandRemove(string user, int amount = 1)
|
||||
{
|
||||
await RaffleCommandHelper("clear");
|
||||
} */
|
||||
ulong userId = Convert.ToUInt64(user.Substring(3, user.Length - 4));
|
||||
int cur = PointsRepository.Total(Context.User.Id.ToString(), Context.Guild.Id.ToString());
|
||||
if (cur > amount)
|
||||
await ReplyAsync($"{Context.User.Mention} has removed {amount} points from <@{userId}> for a total of {PointsRepository.Remove(userId.ToString(), amount, Context.Guild.Id.ToString())} points.", false);
|
||||
else
|
||||
await ReplyAsync($"{Context.User.Mention} has tried to remove {amount} points from <@{userId}> they only had {cur} points. None were taken...", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user