-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
839 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"configurations": [ | ||
|
||
{ | ||
"name": ".NET Core Launch (console)", | ||
"type": "coreclr", | ||
"request": "launch", | ||
"preLaunchTask": "Build UserBot.Cli", | ||
"program": "${workspaceFolder}/UserBot.Cli/bin/Local/net8.0/UserBot.Cli.dll", | ||
"args": [], | ||
"cwd": "${workspaceFolder}", | ||
"stopAtEntry": false, | ||
"console": "internalConsole", | ||
"env": { | ||
"api_id": "24851338", | ||
"api_hash": "82a9e257eb717d3a46f8479cdf307434", | ||
"persist_to": "Memory" | ||
} | ||
} | ||
] | ||
} |
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,24 @@ | ||
{ | ||
"$schema": "https://raw.githubusercontent.com/microsoft/azure-pipelines-task-lib/master/tasks.schema.json", | ||
"version": { | ||
"Major": 2, | ||
"Minor": 0, | ||
"Patch": 0 | ||
}, | ||
"tasks": [ | ||
{ | ||
"label": "Build UserBot.Cli", | ||
"command": "dotnet", | ||
"type": "process", | ||
"args": [ | ||
"build", | ||
"-c:Local", | ||
"-p:BuildFromSource=false", | ||
"${workspaceFolder}/UserBot.Cli/UserBot.Cli.csproj", | ||
"/property:GenerateFullPaths=true", | ||
"/consoleloggerparameters:NoSummary;ForceNoAlign" | ||
], | ||
"problemMatcher": "$msCompile" | ||
} | ||
] | ||
} |
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 |
---|---|---|
@@ -1,15 +1,18 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Telegram.UserBot.Store.Abstractions; | ||
|
||
namespace Telegram.UserBot.Config | ||
{ | ||
public partial interface IUserBotConfig | ||
{ | ||
IUserBotStore? GetSessionStore(); | ||
string? GetConfigVariable(string variable); | ||
string Prompt(string variable); | ||
} | ||
} | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Telegram.UserBot.Store.Abstractions; | ||
|
||
namespace Telegram.UserBot.Config | ||
{ | ||
public partial interface IUserBotConfig | ||
{ | ||
// GetSessionStore GetSessionStore { get; set; } | ||
// IUserBotStore? GetSessionStore(); | ||
string? GetConfigVariable(string variable); | ||
string? Prompt(string variable); | ||
} | ||
|
||
public delegate IUserBotStore GetSessionStore(IServiceProvider services); | ||
} |
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
File renamed without changes.
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 |
---|---|---|
@@ -1,25 +1,39 @@ | ||
namespace Telegram.UserBot.Store.FileSystem; | ||
|
||
using Telegram.UserBot.Store.Abstractions; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Logging.Abstractions; | ||
using Microsoft.Extensions.Options; | ||
|
||
internal class FileUserBotStore : IUserBotStore | ||
public class FileUserBotStore : IUserBotStore, ILog | ||
{ | ||
private readonly string _filePath; | ||
public ILogger? Logger { get; } | ||
private readonly FilePersistedUserBotConfig _options; | ||
|
||
public FileUserBotStore(string? filePath = null) | ||
public FileUserBotStore(IOptions<FilePersistedUserBotConfig> options, ILogger<FileUserBotStore>? logger = null) | ||
{ | ||
_options = options.Value; | ||
|
||
_filePath = | ||
filePath | ||
?? Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), "session.dat"); | ||
_options.FilePath | ||
?? Combine(GetDirectoryName(GetType().Assembly.Location), "session.dat"); | ||
|
||
if (!File.Exists(_filePath)) | ||
{ | ||
File.Create(_filePath).Close(); | ||
Create(_filePath).Close(); | ||
} | ||
|
||
Logger = logger; | ||
} | ||
|
||
public Stream GetStream() | ||
{ | ||
return new FileStream(_filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite); | ||
} | ||
} | ||
|
||
public class FilePersistedUserBotConfig : Telegram.UserBot.Config.UserBotConfig | ||
{ | ||
public string? FilePath { 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,21 @@ | ||
namespace Telegram.UserBot.Store; | ||
|
||
using Telegram.UserBot.Store.Abstractions; | ||
|
||
internal class MemoryUserBotStore : IUserBotStore | ||
{ | ||
private readonly MemoryStream _stream; | ||
|
||
public MemoryUserBotStore() | ||
{ | ||
_stream = new MemoryStream(); | ||
} | ||
|
||
public Stream GetStream() | ||
{ | ||
return _stream; | ||
} | ||
} | ||
namespace Telegram.UserBot.Store; | ||
using Microsoft.Extensions.Logging; | ||
using Telegram.UserBot.Store.Abstractions; | ||
|
||
internal class MemoryUserBotStore : IUserBotStore, ILog | ||
{ | ||
private readonly MemoryStream _stream; | ||
public ILogger? Logger { get; } | ||
|
||
public MemoryUserBotStore(ILogger<MemoryUserBotStore>? logger = null) | ||
{ | ||
_stream = new MemoryStream(); | ||
Logger = logger; | ||
} | ||
|
||
public Stream GetStream() | ||
{ | ||
Logger?.LogInformation("Getting memory stream for userbot session storage."); | ||
return _stream; | ||
} | ||
} |
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.