-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds the extra commands used during SH8
- Loading branch information
Showing
12 changed files
with
235 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Message, TextChannel, DMChannel, User } from 'discord.js'; | ||
import { Command } from 'discord-akairo'; | ||
import { Task, TaskStatus } from '../util/task'; | ||
import { HackathonClient } from '../HackathonClient'; | ||
|
||
export default class IdCommand extends Command { | ||
public constructor() { | ||
super('id', { | ||
aliases: ['id'], | ||
args: [ | ||
{ | ||
'id': 'target', | ||
'type': 'user', | ||
'default': (message: Message) => message.author | ||
} | ||
] | ||
}); | ||
} | ||
|
||
public async exec(message: Message, args: { target: User }) { | ||
const task = new Task({ | ||
title: 'User ID', | ||
issuer: message.author, | ||
description: `${args.target.tag} - your ID is ${message.author.id}`, | ||
status: TaskStatus.Completed | ||
}); | ||
await task.sendTo(message.channel as TextChannel | DMChannel).catch(error => { | ||
(this.client as HackathonClient).config.loggers.bot.warn(error); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Message, TextChannel, DMChannel, User } from 'discord.js'; | ||
import { Command } from 'discord-akairo'; | ||
import { Task, TaskStatus } from '../util/task'; | ||
import { syncAccount, getUser, AuthLevel } from '@unicsmcr/hs_discord_bot_api_client'; | ||
|
||
export default class SyncCommand extends Command { | ||
public constructor() { | ||
super('sync', { | ||
aliases: ['sync'], | ||
args: [ | ||
{ | ||
'id': 'target', | ||
'type': 'user', | ||
'default': (message: Message) => message.author | ||
} | ||
], | ||
// One use per minute to stop abuse of API | ||
cooldown: 60e3, | ||
ratelimit: 1 | ||
}); | ||
} | ||
|
||
public async exec(message: Message, args: { target: User }) { | ||
const task = new Task({ | ||
title: 'User sync', | ||
issuer: message.author, | ||
description: `Syncing account state` | ||
}); | ||
await task.sendTo(message.channel as TextChannel | DMChannel); | ||
try { | ||
let target = args.target; | ||
if (target.id !== message.author.id) { | ||
const issuer = await getUser(message.author.id); | ||
if (issuer.authLevel < AuthLevel.Volunteer) { | ||
target = message.author; | ||
} | ||
} | ||
await syncAccount(target.id); | ||
await task.update({ | ||
status: TaskStatus.Completed, | ||
description: `Synced state for ${target.tag}!` | ||
}); | ||
} catch (error) { | ||
await task.update({ | ||
status: TaskStatus.Failed, | ||
description: `An error occurred processing your request. Try again later.\n\n${error.message}` | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { Message, TextChannel, DMChannel, User } from 'discord.js'; | ||
import { Command } from 'discord-akairo'; | ||
import { Task, TaskStatus } from '../util/task'; | ||
import { getUser, getTeam, APITeam, AuthLevel } from '@unicsmcr/hs_discord_bot_api_client'; | ||
import { HackathonClient } from '../HackathonClient'; | ||
|
||
export default class WhoIsCommand extends Command { | ||
public constructor() { | ||
super('whois', { | ||
aliases: ['whois'], | ||
args: [ | ||
{ | ||
id: 'target', | ||
type: 'user', | ||
prompt: { | ||
start: 'Who would you like to get the details of?', | ||
retry: 'That\'s not a valid member! Try again.' | ||
} | ||
} | ||
] | ||
}); | ||
} | ||
|
||
public async exec(message: Message, args: { target: User }) { | ||
const client = this.client as HackathonClient; | ||
const task = new Task({ | ||
title: 'User info', | ||
issuer: message.author, | ||
description: 'Fetching the info now...' | ||
}); | ||
await task.sendTo(message.channel as TextChannel | DMChannel); | ||
try { | ||
const issuer = await getUser(message.author.id); | ||
if (issuer.authLevel < AuthLevel.Volunteer) { | ||
return task.update({ | ||
status: TaskStatus.Failed, | ||
description: 'Sorry, you need to be a volunteer or organiser to use this command.' | ||
}); | ||
} | ||
|
||
if (message.guild) { | ||
const channel = message.channel as TextChannel; | ||
if (channel.permissionsFor(message.guild.id)?.has('VIEW_CHANNEL')) { | ||
return task.update({ | ||
status: TaskStatus.Failed, | ||
description: 'Sorry, you need to run this in a private channel.' | ||
}); | ||
} | ||
} | ||
|
||
task.status = TaskStatus.Completed; | ||
task.description = ''; | ||
const user = await getUser(args.target.id); | ||
task.addFields( | ||
{ | ||
name: 'Name', | ||
value: user.name | ||
}, | ||
{ | ||
name: 'Auth ID', | ||
value: user.authId | ||
} | ||
); | ||
let team: APITeam | undefined; | ||
if (user.team) { | ||
try { | ||
team = await getTeam(user.team); | ||
task.addFields( | ||
{ | ||
name: 'Team Name', | ||
value: team.name | ||
}, | ||
{ | ||
name: 'Team Auth ID', | ||
value: team.authId | ||
}, | ||
{ | ||
name: 'Team Number', | ||
value: team.teamNumber | ||
} | ||
); | ||
} catch (error) { | ||
task.addFields({ | ||
name: 'Team', | ||
value: `Auth ID: ${user.team} (error fetching more info than this)` | ||
}); | ||
client.config.loggers.bot.warn(`Error fetching team ${user.team}`); | ||
client.config.loggers.bot.warn(error); | ||
} | ||
} | ||
task.update({}); | ||
} catch (error) { | ||
if (error.res?.statusCode === 404) { | ||
task.update({ | ||
status: TaskStatus.Failed, | ||
description: `This account is not linked.` | ||
}); | ||
} else { | ||
task.update({ | ||
status: TaskStatus.Failed, | ||
description: `An error occurred processing your request. Try again later.` | ||
}); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.