Created
March 29, 2019 00:16
-
-
Save hburn7/ea4067ee301c03c1205dd805af7f5ccf to your computer and use it in GitHub Desktop.
ServerMessageLogs.cs : ServerMessageLog.cs :: UserAccounts.cs : UserAccount.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task InitializeAsync(DiscordSocketClient client) | |
{ | |
_client = client; | |
_service = new CommandService(); | |
_service.AddTypeReader(typeof(List<SocketGuildUser>), new ListSocketGuildUserTR()); | |
await _service.AddModulesAsync( | |
Assembly.GetExecutingAssembly(), | |
_services); | |
_client.MessageReceived += HandleCommandAsync; | |
_client.MessageReceived += MessageCache; | |
_client.MessageDeleted += LoggingDeletedMessage; | |
} | |
... | |
private async Task MessageCache(SocketMessage s) //Work on this in the morning xd | |
{ | |
var msg = s as SocketUserMessage; | |
if (msg == null) return; | |
Console.WriteLine("Pass 1"); | |
SocketCommandContext context = new SocketCommandContext(_client, msg); | |
Console.WriteLine("Pass 2"); | |
var currentLog = ServerMessageLogs.GetLog(context.Guild.Id); | |
Console.WriteLine("Pass 3"); | |
currentLog.AddMessage(msg.Content); //Stops here | |
Console.WriteLine("Pass 4"); | |
ServerMessageLogs.SaveServerLogging(); | |
Console.WriteLine("Pass 5"); | |
await msg.Channel.SendMessageAsync("Test complete"); | |
Console.WriteLine("Pass 6"); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace Discord_Bot.Core.Server_Files | |
{ | |
public class ServerMessageLog | |
{ | |
public ulong ID { get; set; } | |
public string ServerName { get; set; } | |
public List<string> LastThousandMessages { get; set; } | |
public ServerMessageLog(ulong id) | |
{ | |
ID = id; | |
ServerName = ""; | |
LastThousandMessages = new List<string>(); | |
} | |
public void AddMessage(string content) | |
{ | |
LastThousandMessages.Add(content); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Discord.WebSocket; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace Discord_Bot.Core.Server_Files | |
{ | |
public static class ServerMessageLogs | |
{ | |
private static List<ServerMessageLog> serverMessageLogs; | |
private static string logFile = "Resources/servermessagelogs.json"; | |
static ServerMessageLogs() | |
{ | |
if(DataStorage2.SaveExists(logFile)) | |
{ | |
serverMessageLogs = DataStorage2.LoadServerMessageLogs(logFile).ToList(); | |
} | |
else | |
{ | |
serverMessageLogs = new List<ServerMessageLog>(); | |
SaveServerLogging(); | |
} | |
} | |
public static ServerMessageLog GetLog(ulong id) | |
{ | |
return GetOrCreateLog(id); | |
} | |
private static ServerMessageLog GetOrCreateLog(ulong id) | |
{ | |
var result = from a in serverMessageLogs | |
where a.ID == id | |
select a; | |
var serverMessageLog = result.FirstOrDefault(); | |
if (serverMessageLogs == null) serverMessageLog = CreateLog(id); | |
return serverMessageLog; | |
} | |
private static ServerMessageLog CreateLog(ulong id) | |
{ | |
var newLog = new ServerMessageLog(id); | |
serverMessageLogs.Add(newLog); | |
SaveServerLogging(); | |
return newLog; | |
} | |
public static void SaveServerLogging() | |
{ | |
DataStorage2.SaveServerLogging(serverMessageLogs, logFile); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{...{... | |
public double LifetimeGambleLosses { get; set; } | |
public double LifetimeGambles { get; set; } | |
public int LifetimeEliteRolls { get; set; } | |
public UserAccount(ulong id) | |
{ | |
ID = id; | |
IsInServers = new List<string>(); | |
IsInServerIDs = new List<ulong>(); | |
Points = 0; | |
EXP = 0; | |
Rep = 0; | |
Blacklisted = 0; | |
LifetimeGambleWins = 0; | |
LifetimeGambleLosses = 0; | |
LifetimeEliteRolls = 0; | |
} | |
public void AddSName(string server) | |
{ | |
IsInServers.Add(server); | |
} | |
...}...} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using Discord.WebSocket; | |
namespace Discord_Bot.Core.UserAccounts | |
{ | |
public static class UserAccounts | |
{ | |
private static List<UserAccount> accounts; | |
private static string accountsFile = "Resources/accounts.json"; | |
static UserAccounts() | |
{ | |
if(DataStorage2.SaveExists(accountsFile)) | |
{ | |
accounts = DataStorage2.LoadUserAccounts(accountsFile).ToList(); | |
} | |
else | |
{ | |
accounts = new List<UserAccount>(); | |
SaveAccounts(); | |
} | |
} | |
public static List<UserAccount> GetAllAccounts() | |
{ | |
return accounts; | |
} | |
public static void SaveAccounts() | |
{ | |
DataStorage2.SaveUserAccounts(accounts, accountsFile); | |
} | |
public static UserAccount GetAccount(SocketUser user) | |
{ | |
return GetOrCreateAccount(user.Id); | |
} | |
public static UserAccount GetAuthor() | |
{ | |
return GetOrCreateAccount(146092837723832320); | |
} | |
private static UserAccount GetOrCreateAccount(ulong id) | |
{ | |
var result = from a in accounts | |
where a.ID == id | |
select a; | |
var account = result.FirstOrDefault(); | |
if(account == null) account = CreateUserAccount(id); | |
return account; | |
} | |
private static UserAccount CreateUserAccount(ulong id) | |
{ | |
var newAccount = new UserAccount(id); | |
accounts.Add(newAccount); | |
SaveAccounts(); | |
return newAccount; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment