-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from Nikolai558/main
Releasing 1.2.0-alpha
- Loading branch information
Showing
26 changed files
with
499 additions
and
182 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using FEBuddyDiscordBot.Models; | ||
using MongoDB.Driver; | ||
|
||
namespace FEBuddyDiscordBot.DataAccess.DB; | ||
|
||
public interface IMongoDbConnection | ||
{ | ||
MongoClient Client { get; } | ||
string DbName { get; } | ||
IMongoCollection<GuildModel> GuildCollection { get; } | ||
string GuildCollectionName { get; } | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using FEBuddyDiscordBot.Models; | ||
|
||
namespace FEBuddyDiscordBot.DataAccess.DB; | ||
|
||
public interface IMongoGuildData | ||
{ | ||
Task CreateGuild(GuildModel guild); | ||
Task<List<GuildModel>> GetAllGuildsAsync(); | ||
Task<GuildModel> GetGuildAsync(string id); | ||
Task UpdateGuild(GuildModel guild); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using MongoDB.Driver; | ||
using FEBuddyDiscordBot.Models; | ||
|
||
namespace FEBuddyDiscordBot.DataAccess.DB; | ||
public class MongoDbConnection : IMongoDbConnection | ||
{ | ||
private string _connectionId = "MongoDB"; | ||
private readonly IConfiguration _config; | ||
private readonly IMongoDatabase _db; | ||
|
||
public string DbName { get; private set; } | ||
public string GuildCollectionName { get; private set; } = "discord-guilds"; | ||
|
||
public MongoClient Client { get; private set; } | ||
public IMongoCollection<GuildModel> GuildCollection { get; private set; } | ||
|
||
public MongoDbConnection(IConfiguration config) | ||
{ | ||
_config = config; | ||
Client = new MongoClient(_config.GetConnectionString(_connectionId)); | ||
DbName = _config["DatabaseName"]; | ||
_db = Client.GetDatabase(DbName); | ||
|
||
GuildCollection = _db.GetCollection<GuildModel>(GuildCollectionName); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using FEBuddyDiscordBot.Models; | ||
using MongoDB.Driver; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace FEBuddyDiscordBot.DataAccess.DB; | ||
public class MongoGuildData : IMongoGuildData | ||
{ | ||
private readonly IMongoCollection<GuildModel> _guilds; | ||
|
||
public MongoGuildData(IMongoDbConnection db) | ||
{ | ||
_guilds = db.GuildCollection; | ||
} | ||
|
||
public async Task<List<GuildModel>> GetAllGuildsAsync() | ||
{ | ||
var results = await _guilds.FindAsync(_ => true); | ||
return results.ToList(); | ||
} | ||
|
||
public async Task<GuildModel> GetGuildAsync(string id) | ||
{ | ||
var results = await _guilds.FindAsync(guild => guild.GuildId == id); | ||
return results.FirstOrDefault(); | ||
} | ||
|
||
public Task CreateGuild(GuildModel guild) | ||
{ | ||
return _guilds.InsertOneAsync(guild); | ||
} | ||
|
||
public Task UpdateGuild(GuildModel guild) | ||
{ | ||
var filter = Builders<GuildModel>.Filter.Eq("Id", guild.GuildId); | ||
return _guilds.ReplaceOneAsync(filter, guild, new ReplaceOptions { IsUpsert = true }); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System.Net; | ||
using System.Text.Json; | ||
using static FEBuddyDiscordBot.Models.VatusaUserModel; | ||
|
||
namespace FEBuddyDiscordBot.DataAccess; | ||
public class VatusaApi | ||
{ | ||
public async Task<VatusaUserData?> GetVatusaUserInfo(ulong MemberId) | ||
{ | ||
string url = $"https://api.vatusa.net/v2/user/{MemberId}?d"; | ||
|
||
using (WebClient webClient = new WebClient()) | ||
{ | ||
try | ||
{ | ||
string jsonResponse = await webClient.DownloadStringTaskAsync(url); | ||
VatusaUserData? userData = JsonSerializer.Deserialize<VatusaUserData>(jsonResponse); | ||
return userData; | ||
} | ||
catch (WebException) | ||
{ | ||
return null; | ||
} | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
global using Discord; | ||
global using Discord.Commands; | ||
global using Discord.WebSocket; | ||
global using Microsoft.Extensions.Configuration; | ||
global using Microsoft.Extensions.DependencyInjection; | ||
global using Microsoft.Extensions.Logging; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using MongoDB.Bson; | ||
using MongoDB.Bson.Serialization.Attributes; | ||
|
||
namespace FEBuddyDiscordBot.Models; | ||
public class GuildModel | ||
{ | ||
[BsonId] | ||
[BsonRepresentation(BsonType.ObjectId)] | ||
public string Id { get; set; } | ||
public string GuildId { get; set; } | ||
public string Name { get; set; } | ||
} |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.