Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Pythonic-Rainbow committed Jan 21, 2024
1 parent 13d10cf commit 6d70e12
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
13 changes: 7 additions & 6 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
```json
{
"discord": "YOUR DISCORD BOT TOKEN",
"coc": "YOUR COC KEY, IT IS IP SENSITIVE"
"coc": "YOUR COC KEY, IT IS IP SENSITIVE",
...
// Please refer to the variable 'definition' in Secrets.cs for all the required data
}
```

Expand All @@ -31,22 +33,22 @@
* `Discord.cs`: Module for interacting with Discord API
* `Sql/`: Interacts with the database

The sole purpose of Program.cs is to fire `InitTask()` in Coc.cs and Discord.cs, then wait forever.
The sole purpose of Program.cs is to fire `InitAsync()` in Coc.cs, Sql/Db.cs and Discord.cs, then wait forever.

Discord.cs requires some time to be 'ready'. When it's ready, it calls `Coc.BotReadyAsync`, which is an endless loop that processes Coc.cs tasks every 5 seconds.

## Coc.cs
When Discord bot is ready, Coc.cs fetches the first copy of clan data. `PollAsync` is called every 5s.

For each call, it fetches the latest Clan data and compares it with the previous one. The result is stored in a `ClanUtil` and is used to dispatch other tasks within Coc.cs. When all the tasks are done, it will replace the previous clan data with the current one.
For each PollAsync call, it fetches the latest Clan data and compares it with the previous one. The result is stored in a `ClanUtil` and is used to dispatch other tasks within Coc.cs. When all the tasks are done, it will replace the previous clan data with the current one.

For each task run, if it needs to interact with Discord, it will call the appropriate methods in `Discord.cs`.

<a name="guidelines"></a>
# Coding Guidelines

1. No variables should be shared between `Discord.cs`, `Coc.cs` and `Db.cs`. If you need functionalities in another module, expose a public method and call it instead.
2. Access modifiers: If a var/func shouldn't be shared, make it private. If a var/func should be shared, make it public.
2. Access modifiers: Make things as restrictive as possible. If a var/func shouldn't be shared, make it private.
3. SQL: All SQL statements should be executed only in `Sql/`. Same logic as above
4. How to order things in a class:
```cs
Expand Down Expand Up @@ -91,5 +93,4 @@ private List<uint> FindFactors(uint number) { }
private async Task ReportToCIA() { }
public uint ComputeFactorial(uint number) { }
public async Task ProcessPayment() { }
```
5. Make things as restrictive as possible.
```
2 changes: 1 addition & 1 deletion Bot/Coc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Hyperstellar;

internal sealed class Coc
internal static class Coc
{
private sealed class ClanUtil
{
Expand Down
6 changes: 3 additions & 3 deletions Bot/Secrets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

internal sealed class Secrets

Check warning on line 3 in Bot/Secrets.cs

View workflow job for this annotation

GitHub Actions / inspect

"[CheckNamespace] Namespace does not correspond to file location, must be: 'Hyperstellar'" on /home/runner/work/Hyperstellar/Hyperstellar/Bot/Secrets.cs(3,46)
{
internal static readonly string s_discord;
internal static readonly string s_coc;
internal static readonly ulong s_botLogId;
internal static readonly string s_discord; // Your Discord bot token
internal static readonly string s_coc; // Your coc token
internal static readonly ulong s_botLogId; // Discord TextChannel ID for the bot to send events to
internal static readonly string s_cocId; // Your coc id, for debugging only

static Secrets()
Expand Down

0 comments on commit 6d70e12

Please sign in to comment.