This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
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 #48 from dmitrydnl/v0.3
V0.3
- Loading branch information
Showing
47 changed files
with
875 additions
and
301 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"welcomeMessage": "Hi, good to see you!", | ||
"mainCommands": "Registration: /reg\nAuthorization: /auth\nInformation about me: /info\nClose chat in any time: /e or /exit", | ||
"information": "This is open source bot for stashing in Telegram Messenger.\nThe code you can find here: https://github.com/dmitrydnl/StashBot", | ||
"registrationWarning": "If you have already registered you will lose all your old data!\nAre you sure? /yes or /no", | ||
"registrationReady": "Input your password or /cancel", | ||
"successRegistration": "Success!\nNow you can auth with password", | ||
"passwordEmpty": "Input password", | ||
"passwordMinLength": "Password min length 12!", | ||
"passwordMaxLength": "Password max length 25!", | ||
"passwordCharacters": "Password can contain only letters, numbers and special characters!", | ||
"authorisationReady": "Input your password or /back", | ||
"successAuthorisation": "Success!", | ||
"failAuthorisation": "WRONG", | ||
"login": "Input message to save it in stash.\nGet messages in stash: /stash\nLogout: /logout", | ||
"logout": "You're logged out" | ||
} |
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,4 @@ | ||
{ | ||
"chatSessionsClearInterval": 10, | ||
"chatSessionLiveTime": 60 | ||
} |
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,21 @@ | ||
namespace StashBot.BotResponses | ||
{ | ||
internal enum ResponseType | ||
{ | ||
WelcomeMessage, | ||
MainCommands, | ||
Information, | ||
RegistrationWarning, | ||
RegistrationReady, | ||
SuccessRegistration, | ||
PasswordEmpty, | ||
PasswordMinLength, | ||
PasswordMaxLength, | ||
PasswordCharacters, | ||
AuthorisationReady, | ||
SuccessAuthorisation, | ||
FailAuthorisation, | ||
Login, | ||
Logout | ||
} | ||
} |
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,46 @@ | ||
using System.IO; | ||
using System.Collections.Generic; | ||
using Newtonsoft.Json; | ||
|
||
namespace StashBot.BotResponses | ||
{ | ||
internal static class TextResponse | ||
{ | ||
private const string BOT_RESPONSES_FILE_NAME = "BotResponses.json"; | ||
|
||
private static Dictionary<ResponseType, string> responses; | ||
|
||
internal static string Get(ResponseType responseType) | ||
{ | ||
return responses[responseType]; | ||
} | ||
|
||
internal static void SetUpResponses() | ||
{ | ||
if (responses != null) | ||
{ | ||
return; | ||
} | ||
|
||
responses = new Dictionary<ResponseType, string>(); | ||
string text = File.ReadAllText(BOT_RESPONSES_FILE_NAME); | ||
dynamic jsonObject = JsonConvert.DeserializeObject<dynamic>(text); | ||
|
||
responses.Add(ResponseType.WelcomeMessage, (string)jsonObject.welcomeMessage); | ||
responses.Add(ResponseType.MainCommands, (string)jsonObject.mainCommands); | ||
responses.Add(ResponseType.Information, (string)jsonObject.information); | ||
responses.Add(ResponseType.RegistrationWarning, (string)jsonObject.registrationWarning); | ||
responses.Add(ResponseType.RegistrationReady, (string)jsonObject.registrationReady); | ||
responses.Add(ResponseType.SuccessRegistration, (string)jsonObject.successRegistration); | ||
responses.Add(ResponseType.PasswordEmpty, (string)jsonObject.passwordEmpty); | ||
responses.Add(ResponseType.PasswordMinLength, (string)jsonObject.passwordMinLength); | ||
responses.Add(ResponseType.PasswordMaxLength, (string)jsonObject.passwordMaxLength); | ||
responses.Add(ResponseType.PasswordCharacters, (string)jsonObject.passwordCharacters); | ||
responses.Add(ResponseType.AuthorisationReady, (string)jsonObject.authorisationReady); | ||
responses.Add(ResponseType.SuccessAuthorisation, (string)jsonObject.successAuthorisation); | ||
responses.Add(ResponseType.FailAuthorisation, (string)jsonObject.failAuthorisation); | ||
responses.Add(ResponseType.Login, (string)jsonObject.login); | ||
responses.Add(ResponseType.Logout, (string)jsonObject.logout); | ||
} | ||
} | ||
} |
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,54 @@ | ||
using System.IO; | ||
using Newtonsoft.Json; | ||
|
||
namespace StashBot.BotSettings | ||
{ | ||
internal static class ChatSessionSettings | ||
{ | ||
private const string BOT_SETTINGS_FILE_NAME = "BotSettings.json"; | ||
|
||
private static bool isSetUp; | ||
private static int chatSessionsClearInterval; | ||
private static int chatSessionLiveTime; | ||
|
||
internal static int ChatSessionsClearInterval | ||
{ | ||
get | ||
{ | ||
SetUpSettings(); | ||
return chatSessionsClearInterval; | ||
} | ||
private set | ||
{ | ||
chatSessionsClearInterval = value; | ||
} | ||
} | ||
|
||
internal static int ChatSessionLiveTime | ||
{ | ||
get | ||
{ | ||
SetUpSettings(); | ||
return chatSessionLiveTime; | ||
} | ||
private set | ||
{ | ||
chatSessionLiveTime = value; | ||
} | ||
} | ||
|
||
private static void SetUpSettings() | ||
{ | ||
if (isSetUp) | ||
{ | ||
return; | ||
} | ||
|
||
string text = File.ReadAllText(BOT_SETTINGS_FILE_NAME); | ||
dynamic jsonObject = JsonConvert.DeserializeObject<dynamic>(text); | ||
ChatSessionsClearInterval = (int)jsonObject.chatSessionsClearInterval; | ||
ChatSessionLiveTime = (int)jsonObject.chatSessionLiveTime; | ||
isSetUp = 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
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,9 @@ | ||
using Telegram.Bot.Types; | ||
|
||
namespace StashBot | ||
{ | ||
internal interface ITelegramUserMessageFactory | ||
{ | ||
ITelegramUserMessage Create(Message telegramMessage); | ||
} | ||
} |
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,24 @@ | ||
namespace StashBot.Module.Database | ||
{ | ||
internal interface IUser | ||
{ | ||
long ChatId | ||
{ | ||
get; | ||
} | ||
|
||
bool IsAuthorized | ||
{ | ||
get; | ||
} | ||
|
||
string EncryptedPassword | ||
{ | ||
get; | ||
} | ||
|
||
void Login(string password); | ||
void Logout(); | ||
bool ValidatePassword(string password); | ||
} | ||
} |
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,69 @@ | ||
using System; | ||
using StashBot.Module.Secure; | ||
|
||
namespace StashBot.Module.Database | ||
{ | ||
internal class User : IUser | ||
{ | ||
public long ChatId | ||
{ | ||
get; | ||
private set; | ||
} | ||
|
||
public bool IsAuthorized | ||
{ | ||
get; | ||
private set; | ||
} | ||
|
||
public string EncryptedPassword | ||
{ | ||
get; | ||
private set; | ||
} | ||
|
||
private readonly string hashPassword; | ||
|
||
internal User(long chatId, string password) | ||
{ | ||
if (string.IsNullOrEmpty(password)) | ||
{ | ||
throw new ArgumentException("Password cannot be null"); | ||
} | ||
|
||
ISecureManager secureManager = ModulesManager.GetModulesManager().GetSecureManager(); | ||
|
||
ChatId = chatId; | ||
IsAuthorized = false; | ||
hashPassword = secureManager.CalculateHash(password); | ||
EncryptedPassword = null; | ||
} | ||
|
||
public void Login(string password) | ||
{ | ||
if (string.IsNullOrEmpty(password)) | ||
{ | ||
throw new ArgumentException("Password cannot be null"); | ||
} | ||
|
||
ISecureManager secureManager = ModulesManager.GetModulesManager().GetSecureManager(); | ||
|
||
EncryptedPassword = secureManager.EncryptWithAes(password); | ||
IsAuthorized = true; | ||
} | ||
|
||
public void Logout() | ||
{ | ||
EncryptedPassword = null; | ||
IsAuthorized = false; | ||
} | ||
|
||
public bool ValidatePassword(string password) | ||
{ | ||
ISecureManager secureManager = ModulesManager.GetModulesManager().GetSecureManager(); | ||
|
||
return secureManager.CompareWithHash(password, hashPassword); | ||
} | ||
} | ||
} |
Oops, something went wrong.