Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Feature command rewrite #862

Closed
wants to merge 16 commits into from
Closed

[WIP] Feature command rewrite #862

wants to merge 16 commits into from

Conversation

Abrynos
Copy link
Member

@Abrynos Abrynos commented Jul 23, 2018

Implements #861 upon completion by rewriting ASFs internal handling of commands and within this change cleans up the huge file Bot.cs already is.

Any advice welcome. 👍

await HandleMessage(notification.chat_group_id, notification.chat_id, notification.steamid_sender, message).ConfigureAwait(false);

string response = await Commands.Parse(this, notification.steamid_sender, message).ConfigureAwait(false);
if(response == null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space + use null or empty for strings (nearly always, unless it matters for you whether you have null or empty).

@@ -1982,7 +1957,12 @@ internal sealed class Bot : IDisposable {
return;
}

await HandleMessage(notification.steamid_friend, message).ConfigureAwait(false);
string response = await Commands.Parse(this, notification.steamid_friend, message).ConfigureAwait(false);
if(response == null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. And you missed return too, so it'll crash instead 😉.

@JustArchi JustArchi added the ✨ Enhancement Issues marked with this label indicate further enhancements to the program, such as new features. label Jul 23, 2018
await HandleMessage(notification.steamid_friend, message).ConfigureAwait(false);
string response = await Commands.Parse(this, notification.steamid_friend, message).ConfigureAwait(false);
if(response == null) {
ArchiLogger.LogNullError(nameof(response));
Copy link
Member

@JustArchi JustArchi Jul 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not blindly copy paste, LogNullError() should be used ONLY for UNEXPECTED errors, null response is entirely expected when the user doesn't have permission to interact with the bot and therefore generates no response.

@Abrynos
Copy link
Member Author

Abrynos commented Jul 23, 2018

I just noticed that thanks to the dicitionary things like !stop bot1, bot2 will not be valid anymore as this would create ("STOP", 2). Users will have to use !stop bot1,bot2 (without a space between bot-names) to avoid the split of bot-names into two arguments -> ("STOP", 1)

(Code coming in next commit)

internal sealed class Commands {
//Because this dictionary maps to async functions we have to make sync functions async with lambdas; e.g. VERSION
//Because for some commands there exist versions with AND without parameters we have to use lambdas to adapt function-interfaces sometimes; e.g. STOP
private static readonly Dictionary<(string Command, byte ArgumentCount), Func<Bot, ulong, string[], Task<string>>> CommandDictionary = new Dictionary<(string Command, byte arguments), Func<Bot, ulong, string[], Task<string>>>() {
Copy link
Member

@JustArchi JustArchi Jul 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong on so many levels. Why do you even put args number there, didn't I just tell you to make static version for each command and in that static version do any kind of arguments parsing? Why do you put lambdas here instead of JUST a pointer to a function that you will await/execute in Parse() function? You didn't just kill old working functionality, but you did it for absolutely no reason - this is unacceptable.

return string.Join(Environment.NewLine, validResults.Select(result => result.Response).Union(extraResponse.ToEnumerable()));
}

private static string GetSingleBotStatusResponse(Bot bot, ulong steamID) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name it the same as parent function, so ResponseStatus. This one accepts less arguments anyway.

@JustArchi
Copy link
Member

Take a break for a week or so (I expect hotfixes in master regarding #810) and then rebase against master, thanks.

@JustArchi JustArchi closed this Jul 24, 2018
@Abrynos
Copy link
Member Author

Abrynos commented Jul 24, 2018

seems legit. v3.3 when all hotfixes are completed?

@JustArchi
Copy link
Member

So definitely NOT 3.3.0.0 😉

@lock lock bot locked as resolved and limited conversation to collaborators Aug 23, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
✨ Enhancement Issues marked with this label indicate further enhancements to the program, such as new features.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants