Skip to content

Commit c21e684

Browse files
committed
changes from latest commits with some patches made
1 parent ca233ed commit c21e684

File tree

7 files changed

+57
-38
lines changed

7 files changed

+57
-38
lines changed

dimscord/gateway.nim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,9 @@ proc startSession(s: Shard, url, query: string) {.async.} =
716716
if not getCurrentExceptionMsg()[0].isAlphaNumeric: return
717717
raise
718718

719+
# todo: Make gateway intent compulsory, and add option of not containing
720+
# message content.
721+
# It will try to forcefully put message content intent if not specified.
719722
proc startSession*(discord: DiscordClient,
720723
autoreconnect = true;
721724
gateway_intents: set[GatewayIntent] = {

dimscord/helpers/channel.nim

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import asyncdispatch, options, json
22
import ../objects, ../constants
33

4+
template startTyping*(c: SomeChannel) =
5+
## Starts typing in a specific Discord channel.
6+
getClient.api.startTyping(c.id)
7+
48
template pin*(m: Message, reason = ""): Future[void] =
59
## Add pinned message.
6-
getClient.api.addChannelMessagePin(m.channel_id, m.id, reason)
10+
getClient.api.pinMessage(m.channel_id, m.id, reason)
711

812
template unpin*(m: Message, reason = ""): Future[void] =
913
## Remove pinned message.
10-
getClient.api.deleteChannelMessagePin(m.channel_id, m.id, reason)
14+
getClient.api.unpinMessage(m.channel_id, m.id, reason)
1115

1216
template getPins*(ch: SomeChannel): Future[seq[Message]] =
1317
## Get channel pins.

dimscord/helpers/guild.nim

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ template beginPrune*(g: Guild;
88
## Begins a guild prune.
99
getClient.api.beginGuildPrune(g.id, days, include_roles, compute_prune_count)
1010

11-
template getPruneCount*(g: Guild; days: int): Future[int] =
11+
template getPruneCount*(g: Guild;
12+
days: int, include_roles: seq[string] = @[]): Future[int] =
1213
## Gets the prune count.
13-
getClient.api.getGuildPruneCount(g.id, days)
14+
getClient.api.getGuildPruneCount(g.id, days, include_roles)
1415

1516
template editMFA*(g: Guild; lvl: MFALevel; reason = ""): Future[MFALevel] =
1617
## Modify Guild MFA Level, requiring guild ownership.
@@ -24,11 +25,12 @@ template edit*(g: Guild;
2425
name, description, region, afk_channel_id, icon = none string;
2526
discovery_splash, owner_id, splash, banner = none string;
2627
system_channel_id, rules_channel_id = none string;
28+
safety_alerts_channel_id = none string;
2729
preferred_locale, public_updates_channel_id = none string;
2830
verification_level, default_message_notifications = none int;
2931
system_channel_flags = none int;
3032
explicit_content_filter, afk_timeout = none int;
31-
features: seq[string] = @[];
33+
features = none seq[string];
3234
premium_progress_bar_enabled = none bool;
3335
reason = ""
3436
): Future[Guild] =
@@ -42,6 +44,7 @@ template edit*(g: Guild;
4244
getClient.api.editGuild(
4345
g.id, name, description, region, afk_channel_id, icon,
4446
discovery_splash, owner_id, splash, banner,
47+
safety_alerts_channel_id,
4548
system_channel_id, rules_channel_id,
4649
preferred_locale, public_updates_channel_id,
4750
verification_level, default_message_notifications,
@@ -57,25 +60,36 @@ template getAuditLogs*(g: Guild;
5760
## Get guild audit logs. The maximum limit is 100.
5861
getClient.api.getGuildAuditLogs(g.id, user_id, before, action_type, limit)
5962

63+
template createRole*(g: Guild,
64+
name: string = "new role";
65+
unicode_emoji, icon = none string;
66+
hoist, mentionable: bool = false;
67+
permissions: set[PermissionFlags] = {};
68+
role_colors = none RoleColors;
69+
color = 0; reason = ""): Future[Role] =
70+
## Creates role.
71+
getClient.api.createGuildRole(g.id,
72+
name, unicode_emoji, icon,
73+
hoist, mentionable, permissions,
74+
role_colors, color, reason)
75+
6076
template deleteRole*(g: Guild; r: Role): Future[void] =
6177
## Deletes a guild role.
6278
getClient.api.deleteGuildRole(g.id, r.id)
6379

6480
template editRole*(g: Guild; r: Role;
6581
name = none string;
82+
permissions = none set[PermissionFlags];
6683
icon, unicode_emoji = none string;
67-
permissions = none PermObj; color = none int;
84+
colors = none RoleColors;
85+
color = none int;
6886
hoist, mentionable = none bool;
6987
reason = ""
7088
): Future[Role] =
7189
## Modifies a guild role.
72-
getClient.api.editGuildRole(
73-
g.id, r.id,
74-
name, icon, unicode_emoji,
75-
permissions, color,
76-
hoist, mentionable,
77-
reason
78-
)
90+
getClient.api.editGuildRole(g.id, r.id,
91+
name, permissions, icon, unicode_emoji,
92+
colors, color, hoist, mentionable)
7993

8094
template getInvites*(g: Guild): Future[seq[InviteMetadata]] =
8195
## Gets guild invites.
@@ -112,10 +126,10 @@ template getBans*(g: Guild): Future[seq[GuildBan]] =
112126
## Gets all the guild bans.
113127
getClient.api.getGuildBans(g.id)
114128

115-
template ban*(g: Guild; m: Member; delete_msg_days: range[0..7] = 0;
129+
template ban*(g: Guild; m: Member; delete_message_seconds: range[0..604800] = 0;
116130
reason = ""): Future[void] =
117131
## Creates a guild ban.
118-
getClient.api.createGuildBan(g.id, m.user.id, delete_msg_days, reason)
132+
getClient.api.createGuildBan(g.id, m.user.id, delete_message_seconds, reason)
119133

120134
template bulkBan*(g: Guild;
121135
user_ids: seq[string];

dimscord/helpers/message.nim

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,22 @@ template reply*(m: Message, content = "";
2828
attachments: seq[Attachment] = @[];
2929
components: seq[MessageComponent] = @[];
3030
files: seq[DiscordFile] = @[];
31+
flags: set[MessageFlags] = {};
3132
stickers: seq[string] = @[];
3233
allowed_mentions = none AllowedMentions;
3334
nonce: Option[string] or Option[int] = none(int);
3435
mention, failifnotexists, tts = false): Future[Message] =
3536
## Replies to a Message.
3637
## - set `mention` to `true` in order to mention the replied message in Discord.
38+
var refr = block:
39+
(if mention: some m.reference else: none MessageReference)
3740
getClient.api.sendMessage(
3841
m.channel_id,
39-
content, tts, nonce,
40-
files, embeds, attachments,
41-
allowed_mentions,
42-
(if mention: some m.reference else: none MessageReference),
43-
components, stickers
42+
content=content, tts=tts, nonce=nonce,
43+
flags=flags, files=files, embeds=embeds,
44+
allowed_mentions=allowed_mentions,
45+
message_reference = refr, components=components,
46+
attachments=attachments, stickers=stickers
4447
)
4548

4649
template editMessage*(c: SomeChannel, m: Message;
@@ -66,13 +69,14 @@ template edit*(m: Message;
6669
components: seq[MessageComponent] = @[];
6770
files: seq[DiscordFile] = @[];
6871
tts = false;
69-
flags = none int): Future[Message] =
72+
flags = none set[MessageFlags]): Future[Message] =
7073
## Edits a Message.
7174
getClient.api.editMessage(
7275
m.channel_id, m.id,
73-
content, tts, flags,
74-
files, embeds, attachments,
75-
components
76+
content=content, tts=tts,
77+
flags=flags,
78+
files=files, embeds=embeds, attachments=attachments,
79+
components=components
7680
)
7781

7882
template delete*(m: Message; reason = ""): Future[void] =

dimscord/restapi/channel.nim

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import ../objects, ../constants, ../helpers
33
import sequtils, requester
44

55
proc startTyping*(api: RestApi, channel_id: string) {.async.} =
6-
## Alias of triggerTypingIndicator
6+
## Starts typing in a specific Discord channel.
77
discard await api.request("POST", endpointTriggerTyping(channel_id))
88

99
proc pinMessage*(api: RestApi,
@@ -241,10 +241,9 @@ proc editGuildChannelPositions*(api: RestApi, guild_id, channel_id: string;
241241
payload.add %*{
242242
"id": channel_id,
243243
"position": %position,
244-
"parent_id": %parent_id,
245244
"lock_permissions": lock_permissions
246245
}
247-
payload.loadNullableOptStr(parent_id)
246+
payload.loadOpt(parent_id)
248247
discard await api.request(
249248
"PATCH",
250249
endpointGuildChannels(guild_id),

dimscord/restapi/guild.nim

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,6 @@ proc editGuildIntegration*(api: RestApi, guild_id, integ_id: string;
389389
let payload = newJObject()
390390

391391
payload.loadOpt(expire_behavior, expire_grace_period, enable_emoticons)
392-
payload.loadNullableOptInt(expire_behavior, expire_grace_period)
393392

394393
discard await api.request(
395394
"PATCH",
@@ -424,7 +423,6 @@ proc editGuildWidget*(api: RestApi, guild_id: string,
424423
let payload = newJObject()
425424

426425
payload.loadOpt(enabled, channel_id)
427-
payload.loadNullableOptStr(channel_id)
428426

429427
result = (await api.request(
430428
"PATCH",
@@ -579,7 +577,7 @@ proc editGuildTemplate*(api: RestApi;
579577
name, description = none string): Future[GuildTemplate] {.async.} =
580578
## Modify a guild template.
581579
let payload = newJObject()
582-
payload.loadNullableOptStr(description)
580+
payload.loadOpt(description)
583581
if name.isSome: payload["name"] = %name
584582
result = (await api.request(
585583
"PATCH", endpointGuildTemplates(gid=guild_id,tid=code)
@@ -606,8 +604,7 @@ proc editUserVoiceState*(api: RestApi,
606604
assert request_to_speak_timestamp.isNone
607605

608606
let payload = %*{"channel_id":channel_id}
609-
payload.loadNullableOptStr(channel_id, request_to_speak_timestamp)
610-
payload.loadOpt(suppress)
607+
payload.loadOpt(channel_id, request_to_speak_timestamp, suppress)
611608

612609
discard await api.request(
613610
"PATCH", endpointGuildVoiceStatesUser(guild_id, user_id),
@@ -637,8 +634,7 @@ proc editGuildWelcomeScreen*(api: RestApi, guild_id: string;
637634
welcome_channels: seq[WelcomeChannel]
638635
]] {.async.} =
639636
let payload = newJObject()
640-
payload.loadOpt(enabled)
641-
payload.loadNullableOptStr(description)
637+
payload.loadOpt(enabled, description)
642638

643639
if welcome_channels.isSome and welcome_channels.get.len == 0:
644640
payload["welcome_channels"] = newJNull()
@@ -766,7 +762,7 @@ proc editGuildSticker*(api: RestApi, guild_id, sticker_id: string;
766762
assert tags.get.len in 2..200
767763
if description.isSome:
768764
assert description.get.len in 2..100
769-
payload.loadNullableOptStr(name, description, tags)
765+
payload.loadOpt(name, description, tags)
770766
result = (await api.request(
771767
"PATCH",
772768
endpointGuildStickers(guild_id, sticker_id),

dimscord/restapi/user.nim

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import asyncdispatch, json, options, jsony, httpclient
22
import ../objects, ../constants
33
import tables, sequtils, strutils
4-
import requester, base64
4+
import requester
55

66
proc getInvite*(api: RestApi, code: string;
77
with_counts, with_expiration = false;
@@ -44,7 +44,7 @@ proc editCurrentMember*(api: RestApi, guild_id: string;
4444
## Modify current member.
4545
## `nick` - some "" to reset nick.
4646
let payload = newJObject()
47-
payload.loadNullableOptStr(nick)
47+
payload.loadOpt(nick)
4848
discard await api.request(
4949
"PATCH",
5050
endpointGuildMembers(guild_id, "@me"),
@@ -131,7 +131,6 @@ proc editCurrentUser*(api: RestApi,
131131
let payload = newJObject()
132132

133133
payload.loadOpt(username, avatar)
134-
payload.loadNullableOptStr(avatar)
135134

136135
result = (await api.request("PATCH", endpointUsers(), $payload)).newUser
137136

0 commit comments

Comments
 (0)