Skip to content

Instantly share code, notes, and snippets.

@KiroMusic
Last active February 23, 2020 20:23
Show Gist options
  • Save KiroMusic/d37a29c75a87866c77359982eb58f5bb to your computer and use it in GitHub Desktop.
Save KiroMusic/d37a29c75a87866c77359982eb58f5bb to your computer and use it in GitHub Desktop.
Ein
using Discord;
using Discord.WebSocket;
using Discord.Commands;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using Newtonsoft.Json;
using System;
namespace Phebest.Accounts
{
public static class GuildAccounts
{
public static List<GuildAccount> accounts;
public static GuildAccount Account;
public static string path = Directory.GetCurrentDirectory();
public static string guilds = "roles.json";
public static string accountsFile = $"{path}/Resources/roles.json";
static GuildAccounts()
{
//accounts = DataStorage.LoadAccounts(accountsFile).ToList();
try
{
if (accounts == null)
{
}
string json = File.ReadAllText($"{Directory.GetCurrentDirectory()}/Resources/roles.json");
accounts = JsonConvert.DeserializeObject<List<GuildAccount>>(json);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
public static void SaveAccounts()
{
//DataStorage.SaveAccounts(accounts, accountsFile);
string json = JsonConvert.SerializeObject(accounts, Formatting.Indented);
File.WriteAllText($"{Directory.GetCurrentDirectory()}/Resources/roles.json", json);
}
public static GuildAccount GetAccount(ulong user)
{
return GetOrCreateAccount(user);
}
public static GuildAccount GetOrCreateAccount(ulong id)
{
if (id == 567743097358909440)
{
var result = from a in accounts
where a.GuildID == id
select a;
var account = result.FirstOrDefault();
if (account == null)
{
var newAccount = new GuildAccount
{
GuildID = id,
UserAccounts = new List<UserAccount>(),
ModLogs = 0,
BanAccounts = new List<BanAccount>(),
BanPermAllow = new List<ulong>(),
EditCasePermAllow = new List<ulong>(),
FullCaptcha = new List<captcha>(),
KickPermAllow = new List<ulong>(),
LogChannel = 0,
MemberCount = 0,
MuteAccounts = new List<MuteAccount>(),
MutedRole = 0,
MutePermAllow = new List<ulong>(),
NotePermAllow = new List<ulong>(),
Prefix = ".",
PunishmentCount = new List<ulong>(),
PurgePermAllow = new List<ulong>(),
RemoveCasePermAllow = new List<ulong>(),
RemoveNotePermAllow = new List<ulong>(),
SittingDucks = new List<SittingDuck>(),
UnbanPermAllow = new List<ulong>(),
UnmutePermAllow = new List<ulong>(),
UserinfoPermAllow = new List<ulong>(),
WarnPermAllow = new List<ulong>(),
WelcomeChannel = 0,
WelcomeEnable = false,
WelcomeMessage = ""
};
accounts.Add(newAccount);
SaveAccounts();
return newAccount;
}
else
{
return account;
}
}
else
{
return null;
}
}
public static UserAccount GetUserAccount(ulong GuildID, ulong ID)
{
var result = from a in GetAccount(GuildID).UserAccounts
where a.ID == ID
select a;
var account = result.FirstOrDefault();
if (account == null)
{
var newAccount = new UserAccount
{
ID = ID,
Balance = 0,
Punishments = new List<Punishment>(),
Avatar = $"{Program.Client.GetGuild(GuildID).GetUser(ID).GetAvatarUrl()}",
DateCreated = Program.Client.GetGuild(GuildID).GetUser(ID).CreatedAt.DateTime,
Name = Program.Client.GetGuild(GuildID).GetUser(ID).Username,
Notes = new List<note>(),
Numbers = $"{Program.Client.GetGuild(GuildID).GetUser(ID)}"
};
GetAccount(GuildID).UserAccounts.Add(newAccount);
SaveAccounts();
return newAccount;
}
else
{
return account;
}
}
public static MuteAccount GetMuteAccount(ulong ID)
{
GuildAccount account = accounts.FirstOrDefault(x => x.GuildID == 567743097358909440);
var accounted = account.MuteAccounts.FirstOrDefault(x => x.ID == ID);
return accounted;
}
public static BanAccount GetBanAccount(ulong GuildID, ulong ID)
{
GuildAccount account = accounts.FirstOrDefault(x => x.GuildID == 567743097358909440);
var accounted = account.BanAccounts.FirstOrDefault(x => x.ID == ID);
return accounted;
}
//public static ShopAccount GetShopAccount(ulong id)
//{
//var result = from a in GetAccount(533987638210723880).ShopAccounts
//where a.ID == id
//select a;
//var account = result.FirstOrDefault();
//return account;
//}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment