/[sudobot]/trunk/src/utils/parseInput.ts
ViewVC logotype

Diff of /trunk/src/utils/parseInput.ts

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 181 by rakin, Mon Jul 29 17:28:54 2024 UTC revision 238 by rakin, Mon Jul 29 17:29:09 2024 UTC
# Line 2  import DiscordClient from '../client/Cli Line 2  import DiscordClient from '../client/Cli
2  import { User, GuildMember, GuildChannel, Role, Guild } from 'discord.js';  import { User, GuildMember, GuildChannel, Role, Guild } from 'discord.js';
3    
4  export async function parseUser(client: DiscordClient, input: string): Promise <User | null> {  export async function parseUser(client: DiscordClient, input: string): Promise <User | null> {
5      if (!/^\<\@(\d+)\>$/.test(input.trim())) {      if (!/^\<\@(\!)?(\d+)\>$/.test(input.trim())) {
6          return null;          return null;
7      }        }  
8    
9      let user: User | null = null;        let user: User | null = null;  
10    
11      try {      try {
12          user = await client.users.fetch(input.trim().substring(2, input.trim().length - 1));          user = await client.users.fetch(input.trim().substring(input.includes('!') ? 3 : 2, input.trim().length - 1));
13      }      }
14      catch (e) {      catch (e) {
15          return null;          return null;
# Line 19  export async function parseUser(client: Line 19  export async function parseUser(client:
19  }  }
20    
21  export async function parseMember(guild: Guild, input: string): Promise <GuildMember | null> {  export async function parseMember(guild: Guild, input: string): Promise <GuildMember | null> {
22      if (!/^\<\@(\d+)\>$/.test(input.trim())) {      if (!/^\<\@(\!)?(\d+)\>$/.test(input.trim())) {
23          return null;          return null;
24      }        }  
25    
26      let user: GuildMember | null = null;          let user: GuildMember | null = null;    
27    
28      try {      try {
29          user = await guild.members.fetch(input.trim().substring(2, input.trim().length - 1));          user = await guild.members.fetch(input.trim().substring(input.includes('!') ? 3 : 2, input.trim().length - 1));
30      }      }
31      catch (e) {      catch (e) {
32          return null;          return null;

Legend:
Removed from v.181  
changed lines
  Added in v.238

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26