-
Notifications
You must be signed in to change notification settings - Fork 16
Feat.report command #165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Feat.report command #165
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,7 @@ import { FishServer, Gamemode, rules, text } from "/config"; | |
| import { command, commandList, fail, formatArg, Perm, Req } from "/frameworks/commands"; | ||
| import type { FishCommandData } from "/frameworks/commands/types"; | ||
| import { Menu } from "/frameworks/menus"; | ||
| import { capitalizeText, Duration, escapeTextDiscord, StringBuilder, StringIO, to2DArray } from "/funcs"; | ||
| import { capitalizeText, Duration, escapeTextDiscord, StringBuilder, StringIO, to2DArray, setToArray } from "/funcs"; | ||
| import { FishEvents, fishPlugin, fishState, ipPortPattern, recentWhispers, tileHistory, uuidPattern } from "/globals"; | ||
| import { FMap } from "/maps"; | ||
| import { FishPlayer } from "/players"; | ||
|
|
@@ -1133,5 +1133,73 @@ Win rate: ${target.stats.gamesWon / target.stats.gamesFinished}` | |
| unit.add(); | ||
| outputSuccess(f`Spawned a ${args.type} that is partly a ${args.base}.`); | ||
| } | ||
| }, | ||
|
|
||
| report: { | ||
| args: [], | ||
| description: 'Report a player to staff with a selected reason.', | ||
| perm: Perm.play, | ||
| requirements: [Req.cooldown(4000)], | ||
| async handler({sender, outputSuccess, outputFail, f}) { | ||
| const onlinePlayers = setToArray(Groups.player); | ||
| if(onlinePlayers.length === 0){ | ||
| outputFail('No players online to report.'); | ||
| return; | ||
| } | ||
| const target = await Menu.menu<mindustryPlayer>( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You've written custom logic to select a player with a menu. The commands framework handles this automatically: specify |
||
| 'Report Player', | ||
| 'Select a player to report.', | ||
| onlinePlayers, | ||
| sender, | ||
| { | ||
| includeCancel: true, | ||
| optionStringifier: player => player.name | ||
| } | ||
| ).catch(() => { | ||
| outputFail('Report cancelled.'); | ||
| return; | ||
| }); | ||
| if(!target) return; | ||
| if(target === sender.player){ | ||
| outputFail('You cannot report yourself.'); | ||
| return; | ||
| } | ||
|
|
||
| const baseReasons = [ | ||
| 'Griefing', | ||
| 'Harassment', | ||
| 'Cheating / Exploiting', | ||
| 'Spam', | ||
| 'Trolling', | ||
| 'Other', | ||
| ]; | ||
| const reasons = target.admin ? [...baseReasons, 'Admin Abuse'] : baseReasons; | ||
| const reason = await Menu.menu<string>( | ||
| 'Report Reason', | ||
| `Select a reason for reporting [accent]${target.name}[]`, | ||
| reasons, | ||
| sender, | ||
| { includeCancel: true } | ||
| ).catch(() => { | ||
| outputFail('Report cancelled.'); | ||
| return; | ||
| }); | ||
| if(!reason) return; | ||
|
|
||
| const issuerName = sender.player?.name ?? 'Unknown'; | ||
| const targetName = target.name; | ||
| const serverName = Gamemode.name(); | ||
| const message = | ||
| `[Report] Server: ${serverName}\n` + | ||
| `Issuer: ${Strings.stripColors(issuerName)}\n` + | ||
| `Target: ${Strings.stripColors(targetName)}${target.admin ? ' (Admin)' : ''}\n` + | ||
| `Reason: ${reason}`; | ||
|
|
||
| api.sendStaffMessage(message, issuerName, (sent) => { | ||
| if(sent) outputSuccess(f`Report sent to staff: ${targetName} for "${reason}".`); | ||
| else outputFail('Failed to send report to staff. Please try again later.'); | ||
| }); | ||
| }, | ||
| } | ||
|
|
||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The check for no players online does not account for the case where the sender is the only player online. In this scenario, the menu will be shown with only the sender as an option, and the error "You cannot report yourself" will only be displayed after the user selects themselves. Consider filtering out the sender from onlinePlayers before checking the length, or checking if there are any other players besides the sender. For example:
const onlinePlayers = setToArray(Groups.player).filter(p => p !== sender.player);