Skip to content

Commit d58d5ea

Browse files
committed
Jsony better error handling (WIP), bump up nim version, some refinements to code
1 parent b1c822e commit d58d5ea

File tree

12 files changed

+405
-370
lines changed

12 files changed

+405
-370
lines changed

dimscord.nimble

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ license = "MIT"
77

88
# Dependencies
99

10-
requires "nim >= 1.2.0", "zippy >= 0.2.1", "ws >= 0.5.0", "regex >= 0.15.0", "libsodium <= 0.6.0", "flatty >= 0.1.2", "jsony >= 1.1.3"
10+
requires "nim >= 2.0.6", "zippy >= 0.2.1", "ws >= 0.5.0", "regex >= 0.15.0", "libsodium <= 0.6.0", "flatty >= 0.1.2", "jsony >= 1.1.3"
1111
requires "opussum >= 0.6.0", "etf#e0b77f7"
1212

1313
task genDoc, "Generates the documentation for dimscord":

dimscord/constants.nim

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
when defined(dimscordDebug):
55
import strformat
66
#{.hint[XDeclaredButNotUsed]: off.} Unsure when am I gonna use this
7-
import strutils, regex
7+
# import strutils, regex
88

99
type
1010
PermissionFlags* = enum
@@ -179,13 +179,10 @@ type
179179
cfRequireTag = 4
180180
cfHideMediaDownloadOptions = 15
181181
SkuFlags* = enum
182+
sfNone,
182183
sfAvailable = 2
183184
sfGuildSubscription = 7
184185
sfUserSubscription = 8
185-
SubscriptionStatus* = enum
186-
ssActive = 0
187-
ssEnding,
188-
ssInactive
189186
const
190187
libName* = "Dimscord"
191188
libVer* = "1.6.0"
@@ -248,14 +245,17 @@ type
248245
mtGuildIncidentReportFalseAlarm = 39
249246
mtPurchaseNotification = 44
250247
mtPollResult = 46
248+
mtUnknown
251249
MessageActivityType* = enum
250+
matNone = 0
252251
matJoin = 1
253252
matSpectate = 2
254253
matListen = 3
255254
matJoinRequest = 5 # nice skip
256255
MessageReferenceType* = enum
257256
mrtDefault = 0
258257
mrtForward = 1
258+
mrtUnknown = 2
259259
ChannelType* = enum
260260
ctGuildText = 0
261261
ctDirect = 1
@@ -315,10 +315,16 @@ type
315315
whIncoming = 1
316316
whFollower = 2
317317
whApplication = 3
318+
EventWebhookStatus* = enum
319+
ewsNone = 0
320+
ewsDisabled = 1
321+
ewsEnabled = 2
322+
ewsDisabledByDiscord = 3
318323
IntegrationExpireBehavior* = enum
319324
iebRemoveRole = 0
320325
iebKick = 1
321326
AuditLogEntryType* = enum
327+
aleUnknown = 0
322328
aleGuildUpdate = 1
323329
aleChannelCreate = 10
324330
aleChannelUpdate = 11
@@ -456,10 +462,12 @@ type
456462
itGroupDm = 1
457463
itFriend = 2
458464
InviteTargetType* = enum
465+
ittUnknown
459466
ittStream = 1
460467
ittEmbeddedApplication = 2
461468
PrivacyLevel* = enum
462469
plGuildOnly = 2
470+
plUnknown
463471
UserPremiumType* = enum
464472
uptNone = 0
465473
uptNitroClassic = 1
@@ -493,18 +501,23 @@ type
493501
mctSeparator = 14
494502
mctContainer = 17
495503
StickerType* = enum
504+
stUnknown
496505
stStandard = 1
497506
stGuild = 2
498507
PollLayoutType* = enum
508+
plNone
499509
plDefault = 1
500510
GuildScheduledEventPrivacyLevel* = enum
501511
splGuildOnly = 2
512+
splUnknown
502513
GuildScheduledEventStatus* = enum
514+
esUnknown
503515
esScheduled = 1
504516
esActive = 2
505517
esCompleted = 3
506518
esCanceled = 4
507519
EntityType* = enum
520+
etNone
508521
etStageInstance = 1
509522
etVoice = 2
510523
etExternal = 3
@@ -539,33 +552,41 @@ type
539552
atPremium = 0
540553
atBasic = 1
541554
ModerationActionType* = enum
555+
matUnknown
542556
matBlockMessage = 1
543557
matSendAlertMessage = 2
544558
matTimeout = 3
545559
ModerationTriggerType* = enum
560+
mttUnknown
546561
mttKeyword = 1
547562
mttHarmfulLink = 2
548563
mttSpam = 3
549564
mttKeywordPreset = 4
550565
mttMentionSpam = 5
551566
KeywordPresetType* = enum
567+
kptUnknown
552568
kptProfanity = 1
553569
kptSexualContent = 2
554570
kptSlurs = 3
555571
ForumSortOrder* = enum
556572
fsoLatestActivity = 0
557573
fsoCreationDate = 1
574+
fsoUnknown
558575
ForumLayout* = enum
559576
flNotSet = 0
560577
flListView = 1
561578
flGalleryView = 2
579+
flUnknown
562580
GuildOnboardingMode* = enum
563581
omDefault = 0,
564-
omAdvanced = 1
582+
omAdvanced = 1,
583+
omUnknown
565584
GuildOnboardingPromptType* = enum
566585
ptMultipleChoice = 0,
567-
ptDropdown = 1
586+
ptDropdown = 1,
587+
ptUnknown
568588
EntitlementType* = enum
589+
etUnknown = 0
569590
etPurchase = 1
570591
etPremiumSubscription,
571592
etDeveloperGift,
@@ -575,11 +596,20 @@ type
575596
etPremiumPurchase,
576597
etApplicationSubscription
577598
SkuType* = enum
578-
stNone = 0 # this is so useless
579599
stDurable = 2
580600
stConsumable = 3
581601
stSubscription = 5
582602
stSubscriptionGroup = 6
603+
stNone
604+
SubscriptionStatus* = enum
605+
ssActive = 0
606+
ssEnding,
607+
ssInactive,
608+
ssUnknown
609+
EntryPointCommandHandlerType* = enum
610+
ephUnknown
611+
ephAppHandler = 1
612+
ephDiscordLaunchActivity = 2
583613
DispatchEvent* = enum
584614
Unknown
585615
VoiceStateUpdate = "VOICE_STATE_UPDATE"

dimscord/dispatch.nim

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import objects, constants
22
import options, json, asyncdispatch
3-
import sequtils, tables, jsony, macros
3+
import sequtils, tables, macros
44
import helpers {.all.}
55
import std/[sugar, strutils]
66

7-
when (NimMajor, NimMinor, NimPatch) >= (1, 6, 0):
8-
{.warning[HoleEnumConv]: off.}
9-
{.warning[CaseTransition]: off.}
7+
{.warning[HoleEnumConv]: off.}
8+
{.warning[CaseTransition]: off.}
109

1110
when defined(dimscordVoice):
1211
from voice import pause, disconnect
@@ -50,12 +49,6 @@ macro checkAndCall(s: Shard, event: static[DispatchEvent], args: varargs[untyped
5049
macro enumElementsAsSet(enm: typed): untyped =
5150
result = newNimNode(nnkCurly).add(enm.getType[1][1..^1])
5251

53-
func fullSet*[T](U: typedesc[T]): set[T] {.inline.} =
54-
when T is Ordinal:
55-
{T.low..T.high}
56-
else: # Hole filled enum
57-
enumElementsAsSet(T)
58-
5952
proc addMsg(c: GuildChannel, m: Message, data: string;
6053
prefs: CacheTablePrefs) {.async.} =
6154
if data.len < prefs.max_message_size:

dimscord/helpers.nim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ proc iconUrl*(g: Guild, fmt = "png"; size = 128): string =
141141
proc `$`*(u: User): string =
142142
## Stringifies a user.
143143
## This would return something like `krisppurg#3211` or `krisp0`
144+
if u.username == "": return u.id
145+
144146
result = u.username
145147
if u.discriminator != "0":
146148
result &= "#" & u.discriminator

0 commit comments

Comments
 (0)