-
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.
- Loading branch information
Showing
68 changed files
with
2,812 additions
and
1,749 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 |
---|---|---|
@@ -1,41 +1,41 @@ | ||
using System; | ||
using System.Reflection; | ||
using WebToTelegramCore.Interfaces; | ||
using WebToTelegramCore.Models; | ||
using WebToTelegramCore.Resources; | ||
using System.Reflection; | ||
using Bnfour.WebToTelegramCore.Interfaces; | ||
using Bnfour.WebToTelegramCore.Models; | ||
using Bnfour.WebToTelegramCore.Resources; | ||
|
||
namespace WebToTelegramCore.BotCommands | ||
namespace Bnfour.WebToTelegramCore.BotCommands; | ||
|
||
/// <summary> | ||
/// Class that handles /about command that shows general info about the bot. | ||
/// </summary> | ||
public class AboutCommand : BotCommandBase, IBotCommand | ||
{ | ||
/// <summary> | ||
/// Class that handles /about command that shows general info about the bot. | ||
/// Command's text. | ||
/// </summary> | ||
public class AboutCommand : BotCommandBase, IBotCommand | ||
{ | ||
/// <summary> | ||
/// Command's text. | ||
/// </summary> | ||
public override string Command => "/about"; | ||
public override string Command => "/about"; | ||
|
||
/// <summary> | ||
/// Constructor. | ||
/// </summary> | ||
public AboutCommand() : base() { } | ||
public override string Description => Locale.AboutDescription; | ||
|
||
/// <summary> | ||
/// Constructor. | ||
/// </summary> | ||
public AboutCommand() : base() { } | ||
|
||
/// <summary> | ||
/// Method to process the command. | ||
/// </summary> | ||
/// <param name="record">Record associated with user who sent the command. | ||
/// Unused here.</param> | ||
/// <returns>Text of message that should be returned to user, with '.' escaped for MarkdownV2</returns> | ||
public override string Process(Record record) | ||
{ | ||
var version = Assembly.GetExecutingAssembly().GetName().Version; | ||
// imagine having to escape dot for "markdown" | ||
var prettyVersion = $"{version.Major}\\.{version.Minor}"; | ||
#if DEBUG | ||
prettyVersion += " debug"; | ||
#endif | ||
return base.Process(record) ?? String.Format(Locale.About, prettyVersion); | ||
} | ||
/// <summary> | ||
/// Method to process the command. | ||
/// </summary> | ||
/// <param name="record">Record associated with user who sent the command. | ||
/// Unused here.</param> | ||
/// <returns>Text of message that should be returned to user, with '.' escaped for MarkdownV2</returns> | ||
public override string Process(Record record) | ||
{ | ||
var version = Assembly.GetExecutingAssembly().GetName().Version; | ||
// imagine having to escape dot for "markdown" | ||
var prettyVersion = $"{version.Major}\\.{version.Minor}"; | ||
#if DEBUG | ||
prettyVersion += " debug"; | ||
#endif | ||
return base.Process(record) ?? string.Format(Locale.About, prettyVersion); | ||
} | ||
} |
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,38 +1,43 @@ | ||
using WebToTelegramCore.Data; | ||
using WebToTelegramCore.Interfaces; | ||
using WebToTelegramCore.Models; | ||
using WebToTelegramCore.Resources; | ||
using Bnfour.WebToTelegramCore.Data; | ||
using Bnfour.WebToTelegramCore.Interfaces; | ||
using Bnfour.WebToTelegramCore.Models; | ||
using Bnfour.WebToTelegramCore.Resources; | ||
|
||
namespace WebToTelegramCore.BotCommands | ||
namespace Bnfour.WebToTelegramCore.BotCommands; | ||
|
||
/// <summary> | ||
/// Base class for commands which are used to anything but to confirm or cancel | ||
/// pending destructive operations. | ||
/// </summary> | ||
public abstract class BotCommandBase : IBotCommand | ||
{ | ||
/// <summary> | ||
/// Base class for commands which are used to anything but to confirm or cancel | ||
/// pending destructive operations. | ||
/// Command text; not implemented in abstract classes. | ||
/// </summary> | ||
public abstract class BotCommandBase : IBotCommand | ||
{ | ||
/// <summary> | ||
/// Command text; not implemented in abstract classes. | ||
/// </summary> | ||
public abstract string Command { get; } | ||
public abstract string Command { get; } | ||
|
||
/// <summary> | ||
/// Short description to be shown alongside the command text in the bot menu | ||
/// within the clients. If empty, the command will not be shown. | ||
/// </summary> | ||
public abstract string Description { get; } | ||
|
||
/// <summary> | ||
/// Constructor. | ||
/// </summary> | ||
public BotCommandBase() { } | ||
/// <summary> | ||
/// Constructor. | ||
/// </summary> | ||
public BotCommandBase() { } | ||
|
||
/// <summary> | ||
/// Method of abstract base class that filters out users with pending | ||
/// cancellations or deletions of token. | ||
/// </summary> | ||
/// <param name="record">Record to process.</param> | ||
/// <returns>Error message if there is an operation pending, | ||
/// or null otherwise.</returns> | ||
public virtual string Process(Record record) | ||
{ | ||
return (!string.IsNullOrEmpty(record.Token) && record.State != RecordState.Normal) | ||
? Locale.ErrorConfirmationPending | ||
: null; | ||
} | ||
/// <summary> | ||
/// Method of abstract base class that filters out users with pending | ||
/// cancellations or deletions of token. | ||
/// </summary> | ||
/// <param name="record">Record to process.</param> | ||
/// <returns>Error message if there is an operation pending, | ||
/// or null otherwise.</returns> | ||
public virtual string Process(Record record) | ||
{ | ||
return (!string.IsNullOrEmpty(record.Token) && record.State != RecordState.Normal) | ||
? Locale.ErrorConfirmationPending | ||
: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,56 @@ | ||
using WebToTelegramCore.Data; | ||
using WebToTelegramCore.Interfaces; | ||
using WebToTelegramCore.Models; | ||
using WebToTelegramCore.Resources; | ||
using Bnfour.WebToTelegramCore.Data; | ||
using Bnfour.WebToTelegramCore.Interfaces; | ||
using Bnfour.WebToTelegramCore.Models; | ||
using Bnfour.WebToTelegramCore.Resources; | ||
|
||
namespace WebToTelegramCore.BotCommands | ||
namespace Bnfour.WebToTelegramCore.BotCommands; | ||
|
||
/// <summary> | ||
/// Class that implements /cancel command to cancel pending destructive | ||
/// operations. | ||
/// </summary> | ||
public class CancelCommand : ConfirmationCommandBase, IBotCommand | ||
{ | ||
/// <summary> | ||
/// Class that implements /cancel command to cancel pending destructive | ||
/// operations. | ||
/// Command's text. | ||
/// </summary> | ||
public override string Command => "/cancel"; | ||
|
||
public override string Description => Locale.CancelDescription; | ||
|
||
/// <summary> | ||
/// Database context to use. | ||
/// </summary> | ||
private readonly RecordContext _context; | ||
|
||
/// <summary> | ||
/// Constructor. | ||
/// </summary> | ||
public class CancelCommand : ConfirmationCommandBase, IBotCommand | ||
public CancelCommand(RecordContext context) : base() | ||
{ | ||
/// <summary> | ||
/// Command's text. | ||
/// </summary> | ||
public override string Command => "/cancel"; | ||
|
||
/// <summary> | ||
/// Constructor. | ||
/// </summary> | ||
public CancelCommand() : base() { } | ||
|
||
/// <summary> | ||
/// Method to process the command. Resets Record's State back to Normal. | ||
/// </summary> | ||
/// <param name="record">Record associated with user who sent the command.</param> | ||
/// <returns>Predefined text if all checks from parent classes passed, | ||
/// corresponding error message otherwise.</returns> | ||
public override string Process(Record record) | ||
_context = context; | ||
} | ||
|
||
/// <summary> | ||
/// Method to process the command. Resets Record's State back to Normal. | ||
/// </summary> | ||
/// <param name="record">Record associated with user who sent the command.</param> | ||
/// <returns>Predefined text if all checks from parent classes passed, | ||
/// corresponding error message otherwise.</returns> | ||
public override string Process(Record record) | ||
{ | ||
string baseResult = base.Process(record); | ||
if (baseResult != null) | ||
{ | ||
string baseResult = base.Process(record); | ||
if (baseResult != null) | ||
{ | ||
return baseResult; | ||
} | ||
|
||
string reply = record.State == RecordState.PendingDeletion | ||
? Locale.CancelDeletion | ||
: Locale.CancelRegeneration; | ||
|
||
record.State = RecordState.Normal; | ||
return reply; | ||
return baseResult; | ||
} | ||
|
||
string reply = record.State == RecordState.PendingDeletion | ||
? Locale.CancelDeletion | ||
: Locale.CancelRegeneration; | ||
|
||
record.State = RecordState.Normal; | ||
_context.SaveChanges(); | ||
return reply; | ||
} | ||
} |
Oops, something went wrong.