diff --git a/docs/modules/bot.md b/docs/cmd/bot.md similarity index 76% rename from docs/modules/bot.md rename to docs/cmd/bot.md index b9e309ea..3f72c247 100644 --- a/docs/modules/bot.md +++ b/docs/cmd/bot.md @@ -10,11 +10,14 @@ This section is for common issues you may encounter and how to resolve them. ## Bot +Description: Basic commands for interacting with FlawBOT. +Aliases: flaw + ### info -Description: Retrieve FlawBOT information. +Description: Retrieve information about FlawBOT. Aliases: about -Parameters: None +Parameters: None. ``` .bot info @@ -22,8 +25,8 @@ Parameters: None ### leave -Description: Make FlawBOT leave the current server. -Aliases: None +Description: Make FlawBOT leave the server. +Aliases: None. Parameters: None. Respond with yes when prompted to complete the action. ``` @@ -34,7 +37,7 @@ Parameters: None. Respond with yes when prompted to complete the action. Description: Ping the FlawBOT client. Aliases: pong -Parameters: None +Parameters: None. ``` .bot ping @@ -42,7 +45,7 @@ Parameters: None ### report -Description: Report a problem with FlawBOT to the developer. Please do not abuse. +Description: Report a problem with FlawBOT to the developer. Aliases: issue Parameters: Detailed description of the issue. Minimum 50 characters. @@ -53,9 +56,8 @@ Parameters: Detailed description of the issue. Minimum 50 characters. ### uptime Description: Retrieve the FlawBOT uptime. -Aliases: time -Parameters: None - +Aliases: None. +Parameters: None. ``` .bot uptime @@ -63,13 +65,14 @@ Parameters: None --- -## Owner Only +## Owner-Only ### activity Description: Set FlawBOT's activity. Aliases: setactivity Parameters: Name of the activity. + ``` .bot activity Team Fortress 2 ``` @@ -78,7 +81,7 @@ Parameters: Name of the activity. Description: Set FlawBOT's avatar. Aliases: setavatar, pfp, photo -Parameters: Image URL. Must be in jpg, png or img format. +Parameters: Image URL. Must be in JPG, PNG or IMG format. ``` .bot avatar [Image URL] @@ -98,7 +101,7 @@ Parameters: Activity Status. Online, Idle, DND or Offline. Description: Set FlawBOT's username. Aliases: setusername, name, setname, nickname, nick -Parameters: New bot username. +Parameters: New nickname for FlawBOT. ``` .sudo setname FlowBOT diff --git a/docs/cmd/channel.md b/docs/cmd/channel.md new file mode 100644 index 00000000..f25aa02a --- /dev/null +++ b/docs/cmd/channel.md @@ -0,0 +1,114 @@ +[issues-link]: https://github.com/CriticalFlaw/FlawBOT/issues +[discord-link]: https://discord.gg/hTdtK9vBhE + +This section is for common issues you may encounter and how to resolve them. + +* For error or issues not on this page, please [open a ticket on our issue tracker][issues-link]. +* For questions not covered in this documentation, [post in our Discord server][discord-link]. + +--- + +## Channel + +Description: Commands for controlling channels. +Aliases: chn, ch, c + +### category + +Description: Create a new channel category. +Aliases: createcategory, newcategory, ct +Parameters: New category name. + +``` +.channel category Welcome +``` + +### clean + +Description: Remove channel messages. +Aliases: clear +Parameters: Number of messages to remove from the current channel. + +``` +.channel clean 10 +``` + +### delete + +Description: Delete a channel. If a channel isn't specified, the current one will be deleted. +Aliases: remove +Parameters: Channel to delete. + +``` +.channel delete #text +``` + +### info + +Description: Print channel information. If a channel isn't specified, the current one will be used. +Aliases: i +Parameters: Channel to retrieve information from. + +``` +.channel info #text +``` + +### purge + +Description: Remove server user's channel messages. +Aliases: None +Parameters: Server user whose messages will be purged. Number of messages to purge. + +``` +.channel purge @CriticalFlaw 10 +``` + +### rename + +Description: Rename a channel. If a channel isn't specified, the current one will be used. +Aliases: setname +Parameters: Channel to rename. New channel name. + +``` +.channel rename #text newtext +``` + +### text + +Description: Create a new text channel. +Aliases: createtext, newtext +Parameters: New text channel name. + +``` +.channel text texts +``` + +### topic + +Description: Set current channel's topic. +Aliases: settopic +Parameters: New channel topic. + +``` +.channel topic Watermelon picking +``` + +### voice + +Description: Create a new voice channel. +Aliases: createvoice, newvoice +Parameters: New voice channel name. + +``` +.channel voice voices +``` + +### vote + +Description: Run a Yay or Nay poll in the current channel. +Aliases: poll +Parameters: Question to be asked in the poll. + +``` +.channel poll Am I correct? +``` \ No newline at end of file diff --git a/docs/cmd/emoji.md b/docs/cmd/emoji.md new file mode 100644 index 00000000..efb586f4 --- /dev/null +++ b/docs/cmd/emoji.md @@ -0,0 +1,64 @@ +[issues-link]: https://github.com/CriticalFlaw/FlawBOT/issues +[discord-link]: https://discord.gg/hTdtK9vBhE + +This section is for common issues you may encounter and how to resolve them. + +* For error or issues not on this page, please [open a ticket on our issue tracker][issues-link]. +* For questions not covered in this documentation, [post in our Discord server][discord-link]. + +--- + +## Emoji + +Description: Commands for managing server emojis. +Aliases: emote + +### add + +Description: Add a new server emoji using a URL image. +Aliases: new, create +Parameters: Image URL. Name for the emoji. + +``` +.emoji add homer [Image URL] +``` + +### delete + +Description: Remove a server emoji. Note: Bots can only delete emojis they created. +Aliases: remove +Parameters: Server emoji to delete. + +``` +.emoji delete :homer: +``` + +### rename + +Description: Rename a server emoji. +Aliases: edit, modify +Parameters: Emoji to rename. New emoji name. + +``` +.emoji rename :homer: homey +``` + +### info + +Description: Retrieve server emoji information. +Aliases: None. +Parameters: Server emoji. + +``` +.emoji info :homer: +``` + +### list + +Description: Retrieve a list of server emojis. +Aliases: print, all +Parameters: None. + +``` +.emoji list +``` \ No newline at end of file diff --git a/docs/cmd/games.md b/docs/cmd/games.md new file mode 100644 index 00000000..ffb8e9fd --- /dev/null +++ b/docs/cmd/games.md @@ -0,0 +1,137 @@ +[issues-link]: https://github.com/CriticalFlaw/FlawBOT/issues +[discord-link]: https://discord.gg/hTdtK9vBhE + +This section is for common issues you may encounter and how to resolve them. + +* For error or issues not on this page, please [open a ticket on our issue tracker][issues-link]. +* For questions not covered in this documentation, [post in our Discord server][discord-link]. + +--- + +## Nintendo + +### amiibo + +Description: Retrieve information about an Amiibo figurine. +Aliases: amib +Parameters: Name of the Amiibo figurine. + +``` +.amiibo luigi +``` + +### pokemon + +Description: Retrieve a Pokémon card. +Aliases: poke, pk +Parameters: Name of the Pokémon. + +``` +.pokemon pikachu +``` + +--- + +## Speedrun + +### speedrun + +Description: Retrieve a game from Speedrun.com. +Aliases: game, run +Parameters: Game to find on Speedrun.com. + +``` +.speedrun Super Mario 64 +``` + +--- + +## Steam + +Description: Commands finding Steam games and users. + +### connect + +Description: Format a game connection string into a link. +Aliases: None. +Parameters: Connection string (ex. IP:PORT)." + +``` +.tf2 connect 123.345.56.789:000; password hello +``` + +### game + +Description: Retrieve information on a Steam game. +Aliases: None. +Parameters: Game to find on Steam. + +``` +.steam game Team Fortress 2 +``` + +### user + +Description: Retrieve information on a Steam user. +Aliases: player +Parameters: User to find on Steam. + +``` +.steam user criticalflaw +``` + +--- + +## Team Fortress 2 + +Description: Commands related to Team Fortress 2. + +### item + +Description: Retrieve an item from the latest TF2 item schema. +Aliases: schema, hat +Parameters: Item to find in the TF2 schema. + +``` +.tf2 item natasha +``` + +### map + +Description: Retrieve map information from teamwork.tf. +Aliases: maps +Parameters: Normalized map name, like pl_upward. + +``` +.tf2 map pl_upward +``` + +### news + +Description: Retrieve the latest news article from teamwork.tf. +Aliases: None +Parameters: Page number from which to retrieve the news. + +``` +.tf2 news +``` + +### creator + +Description: Retrieve a community creator profile from teamwork.tf. +Aliases: creators, youtuber +Parameters: Name of the community creator to find. + +``` +.tf2 creator criticalflaw +``` + +### server + +Description: Retrieve a list of servers with given game-mode. +Aliases: servers +Parameters: Name of the game-mode, like payload. + +``` +.tf2 server payload +``` \ No newline at end of file diff --git a/docs/cmd/misc.md b/docs/cmd/misc.md new file mode 100644 index 00000000..e9e1171b --- /dev/null +++ b/docs/cmd/misc.md @@ -0,0 +1,105 @@ +[issues-link]: https://github.com/CriticalFlaw/FlawBOT/issues +[discord-link]: https://discord.gg/hTdtK9vBhE + +This section is for common issues you may encounter and how to resolve them. + +* For error or issues not on this page, please [open a ticket on our issue tracker][issues-link]. +* For questions not covered in this documentation, [post in our Discord server][discord-link]. + +--- + +## Math + +### math + +Description: Perform a basic math operation. +Aliases: calculate +Parameters: First operand. Operator. Second operand. + +``` +.math 2 + 2 +``` + +### sum + +Description: Calculate the sum of all inputted values. +Aliases: total +Parameters: Numbers to sum up. + +``` +.sum 2 5 3 +``` + +--- + +## Miscellaneous + +### ask + +Description: Ask an 8-ball a question. +Aliases: 8, 8b, 8ball, ball +Parameters: Question to ask the 8-ball. + +``` +.ask Am I lucky? +``` + +### cat + +Description: Retrieve a random cat fact. +Aliases: meow, catfact, randomcat +Parameters: Retrieve a random cat fact and picture. + +``` +.cat +``` + +### coinflip + +Description: Flip a coin. +Aliases: coin, flip +Parameters: None. + +``` +.coinflip +``` + +### diceroll + +Description: Roll a six-sided die. +Aliases: dice, roll, rolldice, die +Parameters: None. + +``` +.diceroll +``` + +### dog + +Description: Retrieve a random dog photo. +Aliases: woof, bark, randomdog +Parameters: None. + +``` +.dog +``` + +### hello + +Description: Say hello to another user to the server. +Aliases: hi, howdy +Parameters: User to say hello to. + +``` +.hello @CriticalFlaw +``` + +### tts + +Description: Make FlawBOT repeat a message as text-to-speech. +Aliases: echo, repeat, say, talk +Parameters: Message for FlawBOT to repeat. + +``` +.tts Hello World +``` \ No newline at end of file diff --git a/docs/modules/music.md b/docs/cmd/music.md similarity index 85% rename from docs/modules/music.md rename to docs/cmd/music.md index 2d1390ec..8fc8f32a 100644 --- a/docs/modules/music.md +++ b/docs/cmd/music.md @@ -13,9 +13,8 @@ This section is for common issues you may encounter and how to resolve them. ### play Description: Play audio from provided URL or search by specified query. -Aliases: None -Parameters: URL from which to play audio - +Aliases: None. +Parameters: URL from which to play audio. ``` .play https://www.youtube.com/watch?v=4JkIs37a2JE @@ -24,9 +23,8 @@ Parameters: URL from which to play audio ### pause Description: Pause audio playback. -Aliases: None -Parameters: None - +Aliases: None. +Parameters: None. ``` .pause @@ -36,8 +34,7 @@ Parameters: None Description: Resume audio playback. Aliases: unpause -Parameters: None - +Parameters: None. ``` .resume @@ -46,9 +43,8 @@ Parameters: None ### stop Description: Stop audio playback and leave the voice channel. -Aliases: None -Parameters: None - +Aliases: None. +Parameters: None. ``` .stop @@ -57,10 +53,9 @@ Parameters: None ### volume Description: Set audio playback volume. -Aliases: None +Aliases: None. Parameters: Audio volume. Can be set to 0-150 (default 100). - ``` .volume 50 ``` @@ -69,8 +64,7 @@ Parameters: Audio volume. Can be set to 0-150 (default 100). Description: Restarts the playback of the current track. Aliases: replay -Parameters: None - +Parameters: None. ``` .replay @@ -80,8 +74,7 @@ Parameters: None Description: Displays information about currently-played track. Aliases: np -Parameters: None - +Parameters: None. ``` .nowplaying diff --git a/docs/cmd/role.md b/docs/cmd/role.md new file mode 100644 index 00000000..6fd64b7f --- /dev/null +++ b/docs/cmd/role.md @@ -0,0 +1,114 @@ +[issues-link]: https://github.com/CriticalFlaw/FlawBOT/issues +[discord-link]: https://discord.gg/hTdtK9vBhE + +This section is for common issues you may encounter and how to resolve them. + +* For error or issues not on this page, please [open a ticket on our issue tracker][issues-link]. +* For questions not covered in this documentation, [post in our Discord server][discord-link]. + +--- + +## Role + +Description: Commands for controlling server roles. +Aliases: roles + +### color + +Description: Change the server role color. +Aliases: setcolor, clr +Parameters: Server role's new HEX color code. Server role to recolor + +``` +.roles color #F2A92B +``` + +### create + +Description: Create a new server role. +Aliases: new +Parameters: New role name. + +``` +.roles create admin +``` + +### delete + +Description: Delete a server role. +Aliases: remove +Parameters: Server role to remove. + +``` +.roles delete admin +``` + +### info + +Description: Retrieve server role information. +Aliases: None. +Parameters: Server role name. + +``` +.roles info admin +``` + +### inrole + +Description: Retrieve a list of users with a given role. +Aliases: None. +Parameters: Server role name. + +``` +.roles inrole admin +``` + +### mention + +Description: Toggle whether this role can be mentioned by others. +Aliases: None. +Parameters: Server role name. + +``` +.roles mentionadmin +``` + +### revoke + +Description: Remove a role from server user. +Aliases: None +Parameters: Server user to get revoked. Server role name. + +``` +.roles revoke @CriticalFlaw admin +``` + +### revokeall + +Description: Remove all role from a server user. +Aliases: None. +Parameters: Server user name. + +``` +.roles revokeall @CriticalFlaw +``` + +### setrole + +Description: Assign a role to server user. +Aliases: addrole +Parameters: Server user name. Server role name. + +``` +.roles setrole @CriticalFlaw admin +``` + +### show + +Description: Toggle whether this role is seen or not. +Aliases: display, hide +Parameters: Server role name. + +``` +.roles show admin +``` \ No newline at end of file diff --git a/docs/cmd/search.md b/docs/cmd/search.md new file mode 100644 index 00000000..58429025 --- /dev/null +++ b/docs/cmd/search.md @@ -0,0 +1,284 @@ +[issues-link]: https://github.com/CriticalFlaw/FlawBOT/issues +[discord-link]: https://discord.gg/hTdtK9vBhE + +This section is for common issues you may encounter and how to resolve them. + +* For error or issues not on this page, please [open a ticket on our issue tracker][issues-link]. +* For questions not covered in this documentation, [post in our Discord server][discord-link]. + +--- + +## Dictionary + +### dictionary + +Description: Retrieve an Urban Dictionary definition for a word or phrase. +Aliases: define, def, dic +Parameters: Word or phrase to find on Urban Dictionary. + +``` +.dictionary Discord +``` + +--- + +## Imgur + +### imgur + +Description: Retrieve an image from Imgur. +Aliases: image +Parameters: Search query to pass to Imgur. + +``` +.imgur Cats +``` + +--- + +## NASA + +### nasa + +Description: Retrieve NASA's Astronomy Picture of the Day. +Aliases: apod, space +Parameters: None. + +``` +.nasa +``` + +--- + +### news + +Description: Retrieve the news articles on a topic from NewsAPI.org. +Aliases: None +Parameters: Article topic to find on NewsAPI.org. + +``` +.news Nintendo +``` + +--- + +## OMDB + +### omdb + +Description: Find a movie or TV show from OMDB. +Aliases: imdb, movie +Parameters: Movie or TV show to find on OMDB. + +``` +.imdb Lego Movie +``` + +--- + +## Google + +### time + +Description: Retrieve the time for specified location +Aliases: clock +Parameters: Location to retrieve time data from + +``` +.time Moscow +``` + + +### weather + +Description: Retrieve the weather for specified location +Aliases: None +Parameters: Location to retrieve weather data from + +``` +.weather Ottawa +``` + +--- + +## Reddit + +### hot + +Description: Get the hottest posts from a given subreddit. +Aliases: None +Parameters: Name of the subreddit. + +``` +.reddit hot tf2 +``` + +### new + +Description: Get the newest posts from a given subreddit. +Aliases: None +Parameters: Name of the subreddit. + +``` +.reddit new tf2 +``` + +### top + +Description: Get the top posts from a given subreddit. +Aliases: None +Parameters: Name of the subreddit. + +``` +.reddit top tf2 +``` + +--- + +## Simpsons + +### simpsons + +Description: Retrieve a random Simpsons screenshot and episode. +Aliases: caramba +Parameters: None. + +``` +.simpsons +``` + +### frinkiac + +Description: Retrieve a random Simpsons gif. +Aliases: doh +Parameters: Inputting anything will add episode information. + +``` +.frinkiac oi +``` + +### futurama + +Description: Retrieve a random Futurama screenshot and episode. +Aliases: bite +Parameters: None. + +``` +.futurama +``` + +### morbotron + +Description: Retrieve a random Futurama gif. +Aliases: neat +Parameters: Inputting anything will add episode information. + +``` +.morbotron oi +``` + +### rick + +Description: Retrieve a random Rick and Morty screenshot and episode. +Aliases: None. +Parameters: None. + +``` +.rick +``` + +### morty + +Description: Retrieve a random Rick and Morty gif. +Aliases: None. +Parameters: Inputting anything will add episode information. + +``` +.morty oi +``` + +--- + +## Twitch + +### twitch + +Description: Retrieve Twitch stream information. +Aliases: None. +Parameters: Channel to find on Twitch. + +``` +.twitch shoutfactorytv +``` + +--- + +## Weather + +### weather + +Description: Retrieve the time and weather for specified location. +Aliases: time +Parameters: Location to get time and weather data from. + +``` +.weather Valve +``` + +--- + +## Wikipedia + +### wiki + +Description: Find articles on Wikipedia. +Aliases: wikipedia +Parameters: Articles to find on Wikipedia. + +``` +.wiki Steam +``` + +--- + +## YouTube + +### channel + +Description: Retrieve a list of YouTube channels. +Aliases: channels, chn +Parameters: Channels to find on YouTube. + +``` +.youtube channel pewdiepie +``` + +### playlist + +Description: Retrieve a list of YouTube playlists. +Aliases: playlists, list +Parameters: Playlists to find on YouTube. + +``` +.youtube playlist Let's Drown Out +``` + +### search + +Description: Retrieve the first YouTube search result. +Aliases: find, watch +Parameters: First result video to find on YouTube. + +``` +.youtube search Accursed Farms +``` + +### video + +Description: Retrieve a list of YouTube videos. +Aliases: videos, vid +Parameters: Videos to find on YouTube. + +``` +.youtube video Zero Punctuation +``` \ No newline at end of file diff --git a/docs/cmd/server.md b/docs/cmd/server.md new file mode 100644 index 00000000..b036e234 --- /dev/null +++ b/docs/cmd/server.md @@ -0,0 +1,73 @@ +[issues-link]: https://github.com/CriticalFlaw/FlawBOT/issues +[discord-link]: https://discord.gg/hTdtK9vBhE + +This section is for common issues you may encounter and how to resolve them. + +* For error or issues not on this page, please [open a ticket on our issue tracker][issues-link]. +* For questions not covered in this documentation, [post in our Discord server][discord-link]. + +--- + +## Server + +Description: Commands for controlling server. +Aliases: guild + +### avatar + +Description: Change the server avatar. +Aliases: setavatar +Parameters: URL image in JPG, PNG or IMG format. +``` +.server avatar [Image URL] +``` + +### info + +Description: Retrieve server information. +Aliases: None. +Parameters: None. + +``` +.server info +``` + +### invite + +Description: Retrieve an instant invite link to the server. +Aliases: None. +Parameters: None. + +``` +.server invite +``` + +### prune + +Description: Prune inactive server members. +Aliases: None. +Parameters: Number of days the user had to be inactive to get pruned. + +``` +.server prune 30 +``` + +### rename + +Description: Change the server name. +Aliases: setname +Parameters: New server name. + +``` +.server rename Cool Discord Server +``` + +### warn + +Description: Direct message user with a warning. +Aliases: scold +Parameters: Server user to warn. Warning message. + +``` +.server warn @CriticalFlaw stop spamming! +``` \ No newline at end of file diff --git a/docs/cmd/user.md b/docs/cmd/user.md new file mode 100644 index 00000000..7120e9eb --- /dev/null +++ b/docs/cmd/user.md @@ -0,0 +1,124 @@ +[issues-link]: https://github.com/CriticalFlaw/FlawBOT/issues +[discord-link]: https://discord.gg/hTdtK9vBhE + +This section is for common issues you may encounter and how to resolve them. + +* For error or issues not on this page, please [open a ticket on our issue tracker][issues-link]. +* For questions not covered in this documentation, [post in our Discord server][discord-link]. + +--- + +## User + +Description: Commands for controlling server users. +Aliases: users, usr + +### avatar + +Description: Retrieve server user's profile picture. +Aliases: getavatar, image, pfp +Parameters: Server user whose profile picture to retrieve. + +``` +.user avatar @CriticalFlaw +``` + +### ban + +Description: Ban a server user. +Aliases: None. +Parameters: Server user to ban. Reason for the ban. + +``` +.user ban @CriticalFlaw Spammer +``` + +### deafen + +Description: Deafen a server user. +Aliases: deaf +Parameters: Server user to deafen. Reason for the deafen. + +``` +.user deafen @CriticalFlaw +``` + +### info + +Description: Retrieve server user's information. +Aliases: None. +Parameters: Server user whose information to retrieve. + +``` +.user info @CriticalFlaw +``` + +### kick + +Description: Kick a user from the server. +Aliases: remove +Parameters: Server user to kick. Reason for the kick. + +``` +.user kick @CriticalFlaw +``` + +### mute + +Description: Mute a server user. +Aliases: silence +Parameters: Server user to mute. Reason for the mute. + +``` +.user mute @CriticalFlaw +``` + +### nickname + +Description: Change server user's nickname. +Aliases: setnick, nick +Parameters: Server user name. New nickname for the name. + +``` +.user nickname @CriticalFlaw critical +``` + +### perms + +Description: Retrieve server user's permissions. +Aliases: None. +Parameters: Server user name. Server channel. + +``` +.user perms @CriticalFlaw #text +``` + +### unban + +Description: Unban a server user. +Aliases: None. +Parameters: Discord user ID to unban from the server. Reason for the unban. + +``` +.user unban 1234567 +``` + +### undeafen + +Description: Undeafen a server user. +Aliases: undeaf +Parameters: Server user to undeafen. Reason for the deafen. + +``` +.user undeafen @CriticalFlaw +``` + +### unmute + +Description: Unmute a server user. +Aliases: None. +Parameters: Server user to unmute. Reason for the deafen. + +``` +.user unmute @CriticalFlaw +``` \ No newline at end of file diff --git a/docs/modules/media.md b/docs/modules/media.md deleted file mode 100644 index f3b63339..00000000 --- a/docs/modules/media.md +++ /dev/null @@ -1,373 +0,0 @@ -[issues-link]: https://github.com/CriticalFlaw/FlawBOT/issues -[discord-link]: https://discord.gg/hTdtK9vBhE - -This section is for common issues you may encounter and how to resolve them. - -* For error or issues not on this page, please [open a ticket on our issue tracker][issues-link]. -* For questions not covered in this documentation, [post in our Discord server][discord-link]. - ---- - -## Amiibo - -### amiibo - -Description: Retrieve Amiibo figurine information -Aliases: amib -Parameters: Name of the Amiibo figurine - -``` -.amiibo luigi -``` - ---- - -## Dictionary - -### dictionary - -Description: Retrieve an Urban Dictionary definition of a word or phrase -Aliases: define, def, dic -Parameters: Query to pass to Urban Dictionary - -``` -.dictionary Discord -``` - ---- - -## Google - -### time - -Description: Retrieve the time for specified location -Aliases: clock -Parameters: Location to retrieve time data from - -``` -.time Moscow -``` - -### news - -Description: Retrieve the latest news articles from NewsAPI.org -Aliases: None -Parameters: Article topic to find on Google News - -``` -.news Nintendo -``` - -### weather - -Description: Retrieve the weather for specified location -Aliases: None -Parameters: Location to retrieve weather data from - -``` -.weather Ottawa -``` - ---- - -## Imgur - -### imgur - -Description: Retrieve an imager from Imgur -Aliases: image -Parameters: Search query to pass to Imgur - -``` -.imgur Cats -``` - ---- - -## NASA - -### nasa - -Description: Retrieve NASA's Astronomy Picture of the Day -Aliases: apod -Parameters: None - -``` -.nasa -``` - ---- - -## OMDB - -### omdb - -Description: Retrieve a movie or TV show from IMDB -Aliases: imdb, movie -Parameters: Movie or TV show to find on IMDB - -``` -.imdb Lego Movie -``` - ---- - -## Pokemon - -### pokemon - -Description: Retrieve a Pokemon card -Aliases: poke, pk -Parameters: Name of the pokemon - -``` -.pokemon pikachu -``` - ---- - -## Reddit - -### hot - -Description: Get hottest posts for a subreddit. -Aliases: None -Parameters: Name of the subreddit. - -``` -.reddit hot tf2 -``` - -### new - -Description: Get newest posts for a subreddit. -Aliases: None -Parameters: Name of the subreddit. - -``` -.reddit new tf2 -``` - -### top - -Description: Get top posts for a subreddit. -Aliases: None -Parameters: Name of the subreddit. - -``` -.reddit top tf2 -``` - ---- - -## Simpsons - -### simpsons - -Description: Retrieve a random Simpsons screenshot and episode -Aliases: caramba -Parameters: None - -``` -.simpsons -``` - -### simpsonsgif - -Description: Retrieve a random Simpsons gif -Aliases: doh -Parameters: Inputting anything will add episode information - -``` -.simpsonsgif oi -``` - -### futurama - -Description: Retrieve a random Futurama screenshot and episode -Aliases: bite -Parameters: None - -``` -.futurama -``` - -### futuramagif - -Description: Retrieve a random Futurama gif -Aliases: neat -Parameters: Inputting anything will add episode information - -``` -.futuramagif oi -``` - -### rick - -Description: Retrieve a random Rick and Morty screenshot and episode -Aliases: morty -Parameters: None - -``` -.rick -``` - -### rickgif - -Description: Retrieve a random Rick and Morty gif -Aliases: mortygif -Parameters: Inputting anything will add episode information - -``` -.rickgif oi -``` - ---- - -## Speedrun - -### speedrun - -Description: Retrieve a game from Speedrun.com -Aliases: game, run -Parameters: Game to search on Speedrun.com - -``` -.speedrun Super Mario 64 -``` - ---- - -## Steam - -### connect - -Description: Format TF2 connection information into a clickable link -Aliases: None -Parameters: Connection string - -``` -.tf2 connect 123.345.56.789:000; password hello -``` - -### game - -Description: Retrieve Steam game information -Aliases: None -Parameters: Game to find on Steam - -``` -.steam game Team Fortress 2 -``` - -### user - -Description: Retrieve Steam user information -Aliases: None -Parameters: User to find on Steam - -``` -.steam user criticalflaw -``` - ---- - -## Team Fortress 2 - -### item - -Description: Retrieve an item from the latest TF2 item schema -Aliases: schema -Parameters: Item to find in the TF2 schema - -``` -.tf2 item natasha -``` - -### map - -Description: Retrieve map information from teamwork.tf -Aliases: maps -Parameters: Normalized map name, like pl_upward - -``` -.tf2 map pl_upward -``` - -### news - -Description: Retrieve the latest news article from teamwork.tf -Aliases: None -Parameters: None - -``` -.tf2 news -``` - -### server - -Description: Retrieve a list of servers with given gamemode -Aliases: servers -Parameters: Name of the gamemode, like payload - -``` -.tf2 server payload -``` - ---- - -## Wikipedia - -### wiki - -Description: Search Wikipedia for a given query -Aliases: wikipedia -Parameters: Query to search on Wikipedia - -``` -.wiki Steam -``` - ---- - -## YouTube - -### channel - -Description: Retrieve a list of YouTube channel given a query -Aliases: channels, chn -Parameters: Channels to find on YouTube - -``` -.youtube channel pewdiepie -``` - -### playlist - -Description: Retrieve a list of YouTube playlists given a query -Aliases: playlists, list -Parameters: Playlist to find on YouTube - -``` -.youtube playlist Let's Drown Out -``` - -### search - -Description: Retrieve the first YouTube search result given a query -Aliases: find -Parameters: First result video to find on YouTube - -``` -.youtube search Accursed Farms -``` - -### video - -Description: Retrieve a list of YouTube videos given a query -Aliases: videos, vid -Parameters: Video to find on YouTube - -``` -.youtube video Zero Punctuation -``` \ No newline at end of file diff --git a/docs/modules/misc.md b/docs/modules/misc.md deleted file mode 100644 index 8d345177..00000000 --- a/docs/modules/misc.md +++ /dev/null @@ -1,149 +0,0 @@ -[issues-link]: https://github.com/CriticalFlaw/FlawBOT/issues -[discord-link]: https://discord.gg/hTdtK9vBhE - -This section is for common issues you may encounter and how to resolve them. - -* For error or issues not on this page, please [open a ticket on our issue tracker][issues-link]. -* For questions not covered in this documentation, [post in our Discord server][discord-link]. - ---- - -## Math - -### math - -Description: Perform a basic math operation -Aliases: calculate -Parameters: First operand. Operator. Second operand - -``` -.math 2 + 2 -``` - -### sum - -Description: Calculate the sum of all inputted values -Aliases: total -Parameters: Numbers to sum up. - -``` -.sum 2 5 3 -``` - ---- - -## Miscellaneous - -### ask - -Description: Ask an 8-ball a question -Aliases: 8b, 8ball, ball -Parameters: Question to ask the 8-ball - -``` -.ask Am I lucky? -``` - -### tts - -Description: Make FlawBOT repeat a message in text-to-speech -Aliases: talk -Parameters: Message for the bot to convert to speech - -``` -.bot tts Hello World -``` - -### cat - -Description: Retrieve a random cat fact -Aliases: catfact -Parameters: None - -``` -.cat -``` - -### randomcat - -Description: Retrieve a random cat photo -Aliases: meow -Parameters: None - -``` -.randomcat -``` - -### coinflip - -Description: Flip a coin -Aliases: coin, flip -Parameters: None - -``` -.coinflip -``` - -### color - -Description: Retrieve color values for a given HEX code -Aliases: clr -Parameters: HEX color code to process - -``` -.color #F2A92B -``` - -### diceroll - -Description: Roll a six-sided die -Aliases: dice, roll, rolldice, die -Parameters: None - -``` -.diceroll -``` - -### randomdog - -Description: Retrieve a random dog photo -Aliases: dog, woof, bark -Parameters: None - -``` -.randomdog -``` - -### hello - -Description: Welcome another user to the server -Aliases: hi, howdy -Parameters: User to say hello to - -``` -.hello @CriticalFlaw -``` - -### ip - -Description: Retrieve IP address geolocation information -Aliases: ipstack, track -Parameters: IP Address - -``` -.ip 123.123.123.123 -``` - ---- - -## Poll - -### poll - -Description: Run a Yay or Nay poll in the current channel -Aliases: None -Parameters: Question to be polled. - -``` -.poll Am I correct? -``` \ No newline at end of file diff --git a/docs/modules/server.md b/docs/modules/server.md deleted file mode 100644 index c9807389..00000000 --- a/docs/modules/server.md +++ /dev/null @@ -1,436 +0,0 @@ -[issues-link]: https://github.com/CriticalFlaw/FlawBOT/issues -[discord-link]: https://discord.gg/hTdtK9vBhE - -This section is for common issues you may encounter and how to resolve them. - -* For error or issues not on this page, please [open a ticket on our issue tracker][issues-link]. -* For questions not covered in this documentation, [post in our Discord server][discord-link]. - ---- - -## Channel - -### category - -Description: Create a new channel category -Aliases: createcategory, newcategory, ct -Parameters: New category name - -``` -.channel category Welcome -``` - -### clean - -Description: Remove channel messages -Aliases: clear -Parameters: Number of message to remove from the current channel - -``` -.channel clean 10 -``` - -### delete - -Description: Delete a channel. If a channel isn't specified, the current one will be deleted -Aliases: remove -Parameters: Channel to delete - -``` -.channel delete #text -``` - -### info - -Description: Print channel information. If a channel isn't specified, the current one will be used -Aliases: i -Parameters: Channel to retrieve information from - -``` -.channel info #text -``` - -### purge - -Description: Remove server user's channel messages -Aliases: None -Parameters: Server user whose messages will be purged. Number of messages to purge. - -``` -.channel purge @CriticalFlaw 10 -``` - -### rename - -Description: Rename a channel. If a channel isn't specified, the current one will be used -Aliases: setname -Parameters: Channel to rename. New channel name. - -``` -.channel rename #text newtext -``` - -### text - -Description: Create a new text channel -Aliases: createtext, newtext, ctc -Parameters: New text channel name - -``` -.channel text texts -``` - -### topic - -Description: Set current channel's topic -Aliases: settopic, st -Parameters: New channel topic - -``` -.channel topic Watermelon picking -``` - -### voice - -Description: Create a new voice channel -Aliases: createvoice, newvoice, cvc -Parameters: New voice channel name - -``` -.channel voice voices -``` - ---- - -## Emoji - -### add - -Description: Add a new server emoji through URL or as an attachment -Aliases: addnew, create -Parameters: Name for the emoji, Image URL - -``` -.emoji add homer [Image URL] -``` - -### delete - -Description: Remove an existing server emoji. Note: Bots can only delete emojis they created. -Aliases: remove, rm, del -Parameters: Server emoji to delete - -``` -.emoji delete :homer: -``` - -### modify - -Description: Edit the name of an existing server emoji. -Aliases: e, edit, rename -Parameters: Emoji to rename, New name - -``` -.emoji rename :homer: homey -``` - -### info - -Description: Retrieve server emoji information -Aliases: i -Parameters: Server emoji information to retrieve - -``` -.emoji info :homer: -``` - -### list - -Description: Retrieve list of server emojis -Aliases: print, l, ls, all -Parameters: None - -``` -.emoji list -``` - ---- - -## Role - -### color - -Description: Set the role color -Aliases: clr -Parameters: HEX color code to set for the role. Server role to recolor. - -``` -.roles color #F2A92B -``` - -### create - -Description: Create a server role -Aliases: new -Parameters: New role name - -``` -.roles create admin -``` - -### delete - -Description: Delete a server role -Aliases: remove -Parameters: Server role to delete - -``` -.roles delete admin -``` - -### info - -Description: Retrieve role information -Aliases: i -Parameters: Server role information to retrieve - -``` -.roles info admin -``` - -### inrole - -Description: Retrieve a list of users in a given role -Aliases: None -Parameters: Server role - -``` -.roles inrole admin -``` - -### mention - -Description: Toggle whether this role can be mentioned by others -Aliases: None -Parameters: Server role to toggle - -``` -.roles mentionadmin -``` - -### revoke - -Description: Remove a role from server user -Aliases: None -Parameters: Server user to get revoked. Server role to revoke from user - -``` -.roles revoke @CriticalFlaw admin -``` - -### revokeall - -Description: Remove all role from server user -Aliases: None -Parameters: Server user to get revoked - -``` -.roles revokeall @CriticalFlaw -``` - -### setrole - -Description: Assign a role to server user -Aliases: addrole, sr -Parameters: Server user to get role assigned. Server role to assign to the user - -``` -.roles setrole @CriticalFlaw admin -``` - -### show - -Description: Toggle whether this role is seen or not -Aliases: display, hide -Parameters: Server role to toggle - -``` -.roles show admin -``` - ---- - -## Server - -### avatar - -Description: Set server avatar -Aliases: setavatar -Parameters: Image URL. Must be in jpg, png or img format. -``` -.server avatar [Image URL] -``` - -### info - -Description: Retrieve server information -Aliases: i -Parameters: None - -``` -.server info -``` - -### invite - -Description: Retrieve an instant invite link to the server -Aliases: None -Parameters: None - -``` -.server invite -``` - -### prune - -Description: Prune inactive server members -Aliases: None -Parameters: Number of days the user had to be inactive to get pruned - -``` -.server prune 30 -``` - -### rename - -Description: Set server name -Aliases: setname -Parameters: New server name - -``` -.server rename Cool Discord Server -``` - -### warn - -Description: Direct message user with a warning -Aliases: scold -Parameters: Server user to warn. Warning message. - -``` -.server warn @CriticalFlaw stop spamming! -``` - ---- - -## User - -### avatar - -Description: Retrieve server user's avatar -Aliases: getavatar -Parameters: Server user whose avatar to retrieve - -``` -.user avatar @CriticalFlaw -``` - -### ban - -Description: Ban server user -Aliases: None -Parameters: Server user to ban. Reason for the ban. (optional) - -``` -.user ban @CriticalFlaw Spammer -``` - -### deafen - -Description: Deafen server user -Aliases: None -Parameters: Server user to deafen. Reason for the deafen. (optional) - -``` -.user deafen @CriticalFlaw -``` - -### info - -Description: Retrieve user information -Aliases: i -Parameters: Server user whose information to retrieve - -``` -.user info @CriticalFlaw -``` - -### kick - -Description: Kick server user -Aliases: None -Parameters: Server user to kick. Reason for the kick. (optional) - -``` -.user kick @CriticalFlaw -``` - -### mute - -Description: Mute server user -Aliases: None -Parameters: Server user to mute. Reason for the mute. (optional) - -``` -.user mute @CriticalFlaw -``` - -### nickname - -Description: Set server user's nickname -Aliases: setnick -Parameters: Server user to nickname. The new nickname - -``` -.user nickname @CriticalFlaw critical -``` - -### perms - -Description: Retrieve server user's permissions -Aliases: prm -Parameters: Server user whose permissions to retrieve. Server channel - -``` -.user perms @CriticalFlaw #text -``` - -### unban - -Description: Unban server user -Aliases: None -Parameters: Discord user ID to unban from the server - -``` -.user unban 1234567 -``` - -### undeafen - -Description: Undeafen server user -Aliases: None -Parameters: Server user to undeafen - -``` -.user undeafen @CriticalFlaw -``` - -### unmute - -Description: Unmute server user -Aliases: None -Parameters: Server user to unmute - -``` -.user unmute @CriticalFlaw -``` \ No newline at end of file diff --git a/mkdocs.yml b/mkdocs.yml index f7922a51..88102d96 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -7,7 +7,7 @@ theme: favicon: resources/favicon.ico palette: scheme: slate - primary: indigo + primary: deep purple accent: orange repo_name: GitHub site_url: https://www.flawbot.criticalflaw.ca/ @@ -16,12 +16,17 @@ nav: - Home: 'index.md' - Installation: 'install.md' - Deployment: 'deploy.md' - - Modules: - - Main: 'modules/bot.md' - - Media: 'modules/media.md' - - Misc: 'modules/misc.md' - - Music: 'modules/music.md' - - Server: 'modules/server.md' + - Commands: + - Bot: 'cmd/bot.md' + - Channel: 'cmd/channel.md' + - Emoji: 'cmd/emoji.md' + - Games: 'cmd/games.md' + - Misc: 'cmd/misc.md' + - Music: 'cmd/music.md' + - Role: 'cmd/role.md' + - Search: 'cmd/search.md' + - Server: 'cmd/server.md' + - User: 'cmd/user.md' markdown_extensions: - admonition - pymdownx.superfences diff --git a/src/FlawBOT.Test/FlawBOT.Test.csproj b/src/FlawBOT.Test/FlawBOT.Test.csproj index b03dd1a1..c8a28c70 100644 --- a/src/FlawBOT.Test/FlawBOT.Test.csproj +++ b/src/FlawBOT.Test/FlawBOT.Test.csproj @@ -1,33 +1,37 @@  - - net5.0 - false - 3.0.0.0 - 3.0.0.0 - 3.0.0 - Igor Nikitin - CriticalFlaw - FlawBOT - Multipurpose Discord bot written in C# using DSharpPlus. Application Tests. - https://github.com/CriticalFlaw/FlawBOT - en-CA - + + net5.0 + false + 3.1.0.0 + 3.1.0.0 + 3.1.0 + Igor Nikitin + CriticalFlaw + FlawBOT + Multipurpose Discord bot written in C# using DSharpPlus. Application Tests. + https://github.com/CriticalFlaw/FlawBOT + en-CA + - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + AnyCPU + - - - + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + - - - + + + + + + + \ No newline at end of file diff --git a/src/FlawBOT.Test/Modules/Amiibo.cs b/src/FlawBOT.Test/Modules/Amiibo.cs deleted file mode 100644 index add568d8..00000000 --- a/src/FlawBOT.Test/Modules/Amiibo.cs +++ /dev/null @@ -1,16 +0,0 @@ -using FlawBOT.Services; -using NUnit.Framework; - -namespace Modules -{ - [TestFixture] - internal class Amiibo - { - [Test] - public void GetAmiiboData() - { - Assert.IsNotNull(AmiiboService.GetAmiiboDataAsync("Donkey Kong").Result); - Assert.IsNull(AmiiboService.GetAmiiboDataAsync("Konkey Dong").Result); - } - } -} \ No newline at end of file diff --git a/src/FlawBOT.Test/Modules/Dictionary.cs b/src/FlawBOT.Test/Modules/Dictionary.cs index 5a471f9a..3f646951 100644 --- a/src/FlawBOT.Test/Modules/Dictionary.cs +++ b/src/FlawBOT.Test/Modules/Dictionary.cs @@ -1,7 +1,7 @@ using FlawBOT.Services; using NUnit.Framework; -namespace Modules +namespace FlawBOT.Test { [TestFixture] internal class Dictionary diff --git a/src/FlawBOT.Test/Modules/Imgur.cs b/src/FlawBOT.Test/Modules/Imgur.cs index 00ff9462..ad1a7f68 100644 --- a/src/FlawBOT.Test/Modules/Imgur.cs +++ b/src/FlawBOT.Test/Modules/Imgur.cs @@ -2,7 +2,7 @@ using FlawBOT.Services; using NUnit.Framework; -namespace Modules +namespace FlawBOT.Test { [TestFixture] internal class Imgur @@ -10,10 +10,12 @@ internal class Imgur [Test] public async Task GetImgurGalleryData() { - var results = await ImgurService.GetImgurGalleryAsync("cats").ConfigureAwait(false); + var results = await ImgurService.GetImgurGalleryAsync(TestSetup.Tokens.ImgurToken, "cats") + .ConfigureAwait(false); Assert.IsNotNull(results); - results = await ImgurService.GetImgurGalleryAsync("dogs").ConfigureAwait(false); + results = await ImgurService.GetImgurGalleryAsync(TestSetup.Tokens.ImgurToken, "dogs") + .ConfigureAwait(false); Assert.IsNotNull(results); } } diff --git a/src/FlawBOT.Test/Modules/Misc.cs b/src/FlawBOT.Test/Modules/Misc.cs index d1726bb7..7cf41a4c 100644 --- a/src/FlawBOT.Test/Modules/Misc.cs +++ b/src/FlawBOT.Test/Modules/Misc.cs @@ -1,7 +1,8 @@ -using FlawBOT.Services; +using System.Net; +using FlawBOT.Services; using NUnit.Framework; -namespace Modules +namespace FlawBOT.Test { [TestFixture] internal class Misc @@ -23,5 +24,11 @@ public void GetRandomAnswer() { Assert.IsNotNull(MiscService.GetRandomAnswer()); } + + [Test] + public void GetIpLocation() + { + Assert.IsNotNull(MiscService.GetIpLocationAsync(IPAddress.Parse("123.123.123.123")).Result.Type); + } } } \ No newline at end of file diff --git a/src/FlawBOT.Test/Modules/NASA.cs b/src/FlawBOT.Test/Modules/NASA.cs index 251c146e..bb79e9ff 100644 --- a/src/FlawBOT.Test/Modules/NASA.cs +++ b/src/FlawBOT.Test/Modules/NASA.cs @@ -1,7 +1,7 @@ using FlawBOT.Services; using NUnit.Framework; -namespace Modules +namespace FlawBOT.Test { [TestFixture] internal class NASA @@ -9,7 +9,7 @@ internal class NASA [Test] public void GetNasaData() { - Assert.IsNotNull(NasaService.GetNasaImageAsync().Result); + Assert.IsNotNull(NasaService.GetNasaImageAsync(TestSetup.Tokens.NasaToken).Result); } } } \ No newline at end of file diff --git a/src/FlawBOT.Test/Modules/News.cs b/src/FlawBOT.Test/Modules/News.cs index 93789d6a..cd4d16bb 100644 --- a/src/FlawBOT.Test/Modules/News.cs +++ b/src/FlawBOT.Test/Modules/News.cs @@ -1,7 +1,7 @@ using FlawBOT.Services; using NUnit.Framework; -namespace Modules +namespace FlawBOT.Test { [TestFixture] internal class News @@ -9,8 +9,9 @@ internal class News [Test] public void GetNewsData() { - Assert.IsTrue(NewsService.GetNewsDataAsync().Result.Status == "ok"); - Assert.IsTrue(NewsService.GetNewsDataAsync("Nintendo").Result.Status == "ok"); + Assert.IsTrue(NewsService.GetNewsDataAsync(TestSetup.Tokens.NewsToken).Result.Status == "ok"); + Assert.IsTrue(NewsService.GetNewsDataAsync(TestSetup.Tokens.NewsToken, "Nintendo").Result.Status == + "ok"); } } } \ No newline at end of file diff --git a/src/FlawBOT.Test/Modules/Nintendo.cs b/src/FlawBOT.Test/Modules/Nintendo.cs new file mode 100644 index 00000000..aab2afff --- /dev/null +++ b/src/FlawBOT.Test/Modules/Nintendo.cs @@ -0,0 +1,30 @@ +using FlawBOT.Services; +using NUnit.Framework; + +namespace FlawBOT.Test +{ + [TestFixture] + internal class Nintendo + { + [Test] + public void GetAmiiboData() + { + Assert.IsNotNull(NintendoService.GetAmiiboDataAsync("Donkey Kong").Result); + Assert.IsNull(NintendoService.GetAmiiboDataAsync("Konkey Dong").Result); + } + + [Test] + public void GetPokemonCards() + { + Assert.Greater(NintendoService.GetPokemonCardsAsync().Result.Cards.Count, 0); + Assert.Greater(NintendoService.GetPokemonCardsAsync("pikachu").Result.Cards.Count, 0); + Assert.AreEqual(NintendoService.GetPokemonCardsAsync("rikachu").Result.Cards.Count, 0); + } + + [Test] + public void UpdatePokemonList() + { + Assert.IsTrue(NintendoService.UpdatePokemonListAsync().Result); + } + } +} \ No newline at end of file diff --git a/src/FlawBOT.Test/Modules/OMDB.cs b/src/FlawBOT.Test/Modules/OMDB.cs index bc901120..52352cb5 100644 --- a/src/FlawBOT.Test/Modules/OMDB.cs +++ b/src/FlawBOT.Test/Modules/OMDB.cs @@ -1,7 +1,7 @@ using FlawBOT.Services; using NUnit.Framework; -namespace Modules +namespace FlawBOT.Test { [TestFixture] internal class OMDB @@ -9,7 +9,7 @@ internal class OMDB [Test] public void GetMovieData() { - Assert.IsNotNull(OmdbService.GetMovieDataAsync("office+space").Result); + Assert.IsNotNull(OmdbService.GetMovieDataAsync(TestSetup.Tokens.OmdbToken, "office+space").Result); } } } \ No newline at end of file diff --git a/src/FlawBOT.Test/Modules/Pokemon.cs b/src/FlawBOT.Test/Modules/Pokemon.cs deleted file mode 100644 index 2c91d353..00000000 --- a/src/FlawBOT.Test/Modules/Pokemon.cs +++ /dev/null @@ -1,23 +0,0 @@ -using FlawBOT.Services; -using NUnit.Framework; - -namespace Modules -{ - [TestFixture] - internal class Pokemon - { - [Test] - public void GetPokemonCards() - { - Assert.Greater(PokemonService.GetPokemonCardsAsync().Result.Cards.Count, 0); - Assert.Greater(PokemonService.GetPokemonCardsAsync("pikachu").Result.Cards.Count, 0); - Assert.AreEqual(PokemonService.GetPokemonCardsAsync("rikachu").Result.Cards.Count, 0); - } - - [Test] - public void UpdatePokemonList() - { - Assert.IsTrue(PokemonService.UpdatePokemonListAsync().Result); - } - } -} \ No newline at end of file diff --git a/src/FlawBOT.Test/Modules/Reddit.cs b/src/FlawBOT.Test/Modules/Reddit.cs index 4b328e3d..8a16980d 100644 --- a/src/FlawBOT.Test/Modules/Reddit.cs +++ b/src/FlawBOT.Test/Modules/Reddit.cs @@ -1,7 +1,7 @@ using FlawBOT.Services; using NUnit.Framework; -namespace Modules +namespace FlawBOT.Test { [TestFixture] internal class Reddit diff --git a/src/FlawBOT.Test/Modules/Simpsons.cs b/src/FlawBOT.Test/Modules/Simpsons.cs index 7025071f..2fcc9434 100644 --- a/src/FlawBOT.Test/Modules/Simpsons.cs +++ b/src/FlawBOT.Test/Modules/Simpsons.cs @@ -1,7 +1,7 @@ using FlawBOT.Services; using NUnit.Framework; -namespace Modules +namespace FlawBOT.Test { [TestFixture] internal class Simpsons diff --git a/src/FlawBOT.Test/Modules/Speedrun.cs b/src/FlawBOT.Test/Modules/Speedrun.cs index 7b3cc471..052c5d68 100644 --- a/src/FlawBOT.Test/Modules/Speedrun.cs +++ b/src/FlawBOT.Test/Modules/Speedrun.cs @@ -1,7 +1,7 @@ using FlawBOT.Services; using NUnit.Framework; -namespace Modules +namespace FlawBOT.Test { [TestFixture] internal class Speedrun diff --git a/src/FlawBOT.Test/Modules/Steam.cs b/src/FlawBOT.Test/Modules/Steam.cs index ff7059aa..eb58d399 100644 --- a/src/FlawBOT.Test/Modules/Steam.cs +++ b/src/FlawBOT.Test/Modules/Steam.cs @@ -2,7 +2,7 @@ using FlawBOT.Services; using NUnit.Framework; -namespace Modules +namespace FlawBOT.Test { [TestFixture] internal class Steam @@ -17,15 +17,17 @@ public void GenerateConnectionLink() [Test] public void GetSteamProfile() { - Assert.IsNotNull(SteamService.GetSteamProfileAsync("criticalflaw").Result); - Assert.IsNull(SteamService.GetSteamProfileAsync("99999999999999999").Result); + Assert.IsNotNull(SteamService.GetSteamProfileAsync(TestSetup.Tokens.SteamToken, "criticalflaw") + .Result); + Assert.IsNull(SteamService.GetSteamProfileAsync(TestSetup.Tokens.SteamToken, "99999999999999999") + .Result); } [Test] [Order(1)] public void UpdateSteamAppList() { - Assert.IsTrue(SteamService.UpdateSteamAppListAsync().Result); + Assert.IsTrue(SteamService.UpdateSteamAppListAsync(TestSetup.Tokens.SteamToken).Result); } } } \ No newline at end of file diff --git a/src/FlawBOT.Test/Modules/TeamFortress.cs b/src/FlawBOT.Test/Modules/TeamFortress.cs index 312961aa..86439d73 100644 --- a/src/FlawBOT.Test/Modules/TeamFortress.cs +++ b/src/FlawBOT.Test/Modules/TeamFortress.cs @@ -1,7 +1,7 @@ using FlawBOT.Services; using NUnit.Framework; -namespace Modules +namespace FlawBOT.Test { [TestFixture] internal class TeamFortress @@ -9,15 +9,18 @@ internal class TeamFortress [Test] public void GetMapStats() { - Assert.IsNotNull(TeamFortressService.GetMapStatsAsync("pl_upward").Result); - Assert.IsNotNull(TeamFortressService.GetMapStatsAsync("upward").Result); - Assert.IsNull(TeamFortressService.GetMapStatsAsync("bonewards").Result); + Assert.IsNotNull(TeamFortressService.GetMapStatsAsync(TestSetup.Tokens.TeamworkToken, "pl_upward") + .Result); + Assert.IsNotNull(TeamFortressService.GetMapStatsAsync(TestSetup.Tokens.TeamworkToken, "upward") + .Result); + Assert.IsNull(TeamFortressService.GetMapStatsAsync(TestSetup.Tokens.TeamworkToken, "bonewards") + .Result); } [Test] public void GetNewsOverview() { - Assert.IsNotNull(TeamFortressService.GetNewsArticlesAsync().Result); + Assert.IsNotNull(TeamFortressService.GetNewsArticlesAsync(TestSetup.Tokens.TeamworkToken).Result); } [Test] @@ -31,15 +34,17 @@ public void GetSchemaItem() [Test] public void GetServers() { - Assert.IsNotNull(TeamFortressService.GetServersByGameModeAsync("payload").Result); - Assert.IsNull(TeamFortressService.GetServersByGameModeAsync("payloader").Result); + Assert.IsNotNull(TeamFortressService + .GetServersByGameModeAsync(TestSetup.Tokens.TeamworkToken, "payload").Result); + Assert.IsNull(TeamFortressService + .GetServersByGameModeAsync(TestSetup.Tokens.TeamworkToken, "payloader").Result); } [Test] [Order(1)] public void UpdateTf2Schema() { - Assert.IsTrue(TeamFortressService.UpdateTf2SchemaAsync().Result); + Assert.IsTrue(TeamFortressService.UpdateTf2SchemaAsync(TestSetup.Tokens.SteamToken).Result); } } } \ No newline at end of file diff --git a/src/FlawBOT.Test/Modules/Twitch.cs b/src/FlawBOT.Test/Modules/Twitch.cs index 8ff00279..c83840c2 100644 --- a/src/FlawBOT.Test/Modules/Twitch.cs +++ b/src/FlawBOT.Test/Modules/Twitch.cs @@ -1,7 +1,7 @@ using FlawBOT.Services; using NUnit.Framework; -namespace Modules +namespace FlawBOT.Test { [TestFixture] internal class Twitch @@ -9,7 +9,7 @@ internal class Twitch [Test] public void GetStreamData() { - Assert.IsNotNull(TwitchService.GetTwitchDataAsync("rifftrax")); + Assert.IsNotNull(TwitchService.GetTwitchDataAsync(TestSetup.Tokens.TwitchToken, "rifftrax")); } } } \ No newline at end of file diff --git a/src/FlawBOT.Test/Modules/Weather.cs b/src/FlawBOT.Test/Modules/Weather.cs new file mode 100644 index 00000000..e0e3efe7 --- /dev/null +++ b/src/FlawBOT.Test/Modules/Weather.cs @@ -0,0 +1,16 @@ +using System.Net; +using FlawBOT.Services; +using NUnit.Framework; + +namespace FlawBOT.Test +{ + [TestFixture] + internal class Weather + { + [Test] + public void GetWeatherData() + { + Assert.IsNotNull(WeatherService.GetWeatherDataAsync(TestSetup.Tokens.WeatherToken, "Toronto").Result); + } + } +} \ No newline at end of file diff --git a/src/FlawBOT.Test/Modules/Wikipedia.cs b/src/FlawBOT.Test/Modules/Wikipedia.cs index 05f2a1d9..4bba904d 100644 --- a/src/FlawBOT.Test/Modules/Wikipedia.cs +++ b/src/FlawBOT.Test/Modules/Wikipedia.cs @@ -1,7 +1,7 @@ using FlawBOT.Services; using NUnit.Framework; -namespace Modules +namespace FlawBOT.Test { [TestFixture] internal class Wikipedia diff --git a/src/FlawBOT.Test/Modules/World.cs b/src/FlawBOT.Test/Modules/World.cs deleted file mode 100644 index 29ff29d5..00000000 --- a/src/FlawBOT.Test/Modules/World.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Net; -using FlawBOT.Services; -using NUnit.Framework; - -namespace Modules -{ - [TestFixture] - internal class World - { - [Test] - public void GetIpLocation() - { - Assert.IsNotNull(WorldService.GetIpLocationAsync(IPAddress.Parse("123.123.123.123")).Result.Type); - } - - [Test] - public void GetWeatherData() - { - Assert.IsNotNull(WorldService.GetWeatherDataAsync("Ottawa").Result); - Assert.IsNull(WorldService.GetWeatherDataAsync("Ottura").Result); - } - } -} \ No newline at end of file diff --git a/src/FlawBOT.Test/TestSetup.cs b/src/FlawBOT.Test/TestSetup.cs index 4949bf5a..e376cd2c 100644 --- a/src/FlawBOT.Test/TestSetup.cs +++ b/src/FlawBOT.Test/TestSetup.cs @@ -1,20 +1,28 @@ using System.IO; using System.Text; using FlawBOT.Common; -using FlawBOT.Models; using Newtonsoft.Json; using NUnit.Framework; -namespace GamesModule +namespace FlawBOT.Test { [SetUpFixture] - internal class TestSetup + public class TestSetup { + public static Tokens Tokens { get; set; } + [OneTimeSetUp] public void PreTest() { + if (!File.Exists("config.json")) return; var json = new StreamReader(File.OpenRead("config.json"), new UTF8Encoding(false)).ReadToEnd(); - SharedData.Tokens = JsonConvert.DeserializeObject(json); + Tokens = JsonConvert.DeserializeObject(json)?.Tokens; + } + + [OneTimeTearDown] + public void PostTest() + { + // Nothing... } } } \ No newline at end of file diff --git a/src/FlawBOT/Common/HelpFormatter.cs b/src/FlawBOT/Common/HelpFormatter.cs index 385315f8..eb6924e6 100644 --- a/src/FlawBOT/Common/HelpFormatter.cs +++ b/src/FlawBOT/Common/HelpFormatter.cs @@ -19,7 +19,7 @@ public HelpFormatter(CommandContext ctx) : base(ctx) { _output = new DiscordEmbedBuilder() .WithColor(DiscordColor.Turquoise) - .WithUrl(SharedData.GitHubLink + "wiki"); + .WithUrl(Program.Settings.GitHubLink + "wiki"); } public override CommandHelpMessage Build() diff --git a/src/FlawBOT/Common/MusicPlayer.cs b/src/FlawBOT/Common/MusicPlayer.cs index d479b972..bbebb4cb 100644 --- a/src/FlawBOT/Common/MusicPlayer.cs +++ b/src/FlawBOT/Common/MusicPlayer.cs @@ -115,7 +115,7 @@ public void Enqueue(MusicData item) public async Task CreatePlayerAsync(DiscordChannel channel) { - if (Player != null && Player.IsConnected) return; + if (Player is {IsConnected: true}) return; Player = await LavaLink.Node.ConnectAsync(channel); diff --git a/src/FlawBOT/Common/SharedData.cs b/src/FlawBOT/Common/SharedData.cs index 17d2a949..6e0d1d3f 100644 --- a/src/FlawBOT/Common/SharedData.cs +++ b/src/FlawBOT/Common/SharedData.cs @@ -1,21 +1,57 @@ using System; using System.Reflection; +using System.Text.Json.Serialization; using DSharpPlus.Entities; -using FlawBOT.Models; using FlawBOT.Properties; +using Newtonsoft.Json; namespace FlawBOT.Common { - public static class SharedData + public class BotSettings { - public static string Name { get; } = "FlawBOT"; - public static string Version { get; } = Assembly.GetExecutingAssembly().GetName().Version?.ToString(); - public static string GitHubLink { get; } = Resources.URL_BOT_GitHub; - public static string InviteLink { get; } = Resources.URL_BOT_Invite; - public static DiscordColor DefaultColor { get; } = new("#00FF7F"); - public static DateTime ProcessStarted { get; set; } - public static TokenData Tokens { get; set; } = new(); - public static int ShardCount { get; } = 1; + public DiscordColor DefaultColor = new("#00FF7F"); + [JsonPropertyName("Name")] public string Name; + [JsonPropertyName("Prefix")] public string Prefix; + [JsonPropertyName("ShardCount")] public int ShardCount; + [JsonPropertyName("Tokens")] public Tokens Tokens; + [JsonPropertyName("Lavalink")] public bool UseLavalink; + public string Version { get; } = Assembly.GetExecutingAssembly().GetName().Version?.ToString(); + public string GitHubLink { get; } = Resources.URL_BOT_GitHub; + public string InviteLink { get; } = Resources.URL_BOT_Invite; + public string DocsLink { get; } = Resources.URL_BOT_Docs; + public DateTime ProcessStarted { get; set; } + } + + public class Tokens + { + [JsonProperty("Discord")] public string DiscordToken { get; set; } + + [JsonProperty("Steam", NullValueHandling = NullValueHandling.Ignore)] + public string SteamToken { get; set; } + + [JsonProperty("Imgur", NullValueHandling = NullValueHandling.Ignore)] + public string ImgurToken { get; set; } + + [JsonProperty("OMDB", NullValueHandling = NullValueHandling.Ignore)] + public string OmdbToken { get; set; } + + [JsonProperty("Twitch", NullValueHandling = NullValueHandling.Ignore)] + public string TwitchToken { get; set; } + + [JsonProperty("NASA", NullValueHandling = NullValueHandling.Ignore)] + public string NasaToken { get; set; } + + [JsonProperty("TeamworkTF", NullValueHandling = NullValueHandling.Ignore)] + public string TeamworkToken { get; set; } + + [JsonProperty("News", NullValueHandling = NullValueHandling.Ignore)] + public string NewsToken { get; set; } + + [JsonProperty("Weather", NullValueHandling = NullValueHandling.Ignore)] + public string WeatherToken { get; set; } + + [JsonProperty("YouTube", NullValueHandling = NullValueHandling.Ignore)] + public string YouTubeToken { get; set; } } public enum ResponseType diff --git a/src/FlawBOT/FlawBOT.cs b/src/FlawBOT/FlawBOT.cs index 213f2052..f8b10746 100644 --- a/src/FlawBOT/FlawBOT.cs +++ b/src/FlawBOT/FlawBOT.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using System.Linq; using System.Threading.Tasks; using DSharpPlus; @@ -23,10 +24,13 @@ internal sealed class FlawBot { public FlawBot(int shardId = 0) { + // Get Settings + var settings = Program.Settings; + // Setup Client Client = new DiscordClient(new DiscordConfiguration { - Token = SharedData.Tokens.DiscordToken, + Token = settings.Tokens.DiscordToken, TokenType = TokenType.Bot, AutoReconnect = true, ReconnectIndefinitely = true, @@ -36,12 +40,12 @@ public FlawBot(int shardId = 0) MessageCacheSize = 2048, LogTimestampFormat = "yyyy-MM-dd HH:mm:ss zzz", ShardId = shardId, - ShardCount = SharedData.ShardCount + ShardCount = settings.ShardCount }); Client.Ready += Client_Ready; Client.GuildAvailable += Client_GuildAvailable; - Client.ClientErrored += Client_ClientErrored; - Client.SocketErrored += Client_SocketErrored; + Client.ClientErrored += Client_ClientError; + Client.SocketErrored += Client_SocketError; Client.VoiceStateUpdated += Client_VoiceStateUpdated; // Setup Services @@ -64,9 +68,8 @@ public FlawBot(int shardId = 0) Services = Services }); Commands.CommandExecuted += Command_Executed; - Commands.CommandErrored += Command_Errored; + Commands.CommandErrored += Command_Error; Commands.SetHelpFormatter(); - Commands.RegisterCommands(); Commands.RegisterCommands(); Commands.RegisterCommands(); Commands.RegisterCommands(); @@ -77,9 +80,8 @@ public FlawBot(int shardId = 0) Commands.RegisterCommands(); Commands.RegisterCommands(); Commands.RegisterCommands(); + Commands.RegisterCommands(); Commands.RegisterCommands(); - Commands.RegisterCommands(); - Commands.RegisterCommands(); Commands.RegisterCommands(); Commands.RegisterCommands(); Commands.RegisterCommands(); @@ -90,7 +92,7 @@ public FlawBot(int shardId = 0) Commands.RegisterCommands(); Commands.RegisterCommands(); Commands.RegisterCommands(); - Commands.RegisterCommands(); + Commands.RegisterCommands(); Commands.RegisterCommands(); // Setup Interactivity @@ -108,16 +110,16 @@ public FlawBot(int shardId = 0) }); // Setup Lavalink - //Lavalink = Client.UseLavalink(); - //Process.Start("java", $"-jar {Directory.GetCurrentDirectory()}\\Lavalink.jar"); + if (settings.UseLavalink && File.Exists($"{Directory.GetCurrentDirectory()}\\Lavalink.jar")) + Lavalink = Client.UseLavalink(); // Start the uptime counter - Console.Title = $"{SharedData.Name}-{SharedData.Version}"; - SharedData.ProcessStarted = DateTime.Now; + Console.Title = $"{settings.Name}-{settings.Version}"; + settings.ProcessStarted = DateTime.Now; } private IServiceProvider Services { get; } - private static EventId EventId { get; } = new(1000, SharedData.Name); + private static EventId EventId { get; } = new(1000, Program.Settings.Name); private DiscordClient Client { get; } private CommandsNextExtension Commands { get; } private InteractivityExtension Interactivity { get; } @@ -127,10 +129,13 @@ public FlawBot(int shardId = 0) public async Task RunAsync() { // Update any other services that are being used. - Client.Logger.LogInformation(EventId, "Loading..."); - await SteamService.UpdateSteamAppListAsync().ConfigureAwait(false); - await TeamFortressService.UpdateTf2SchemaAsync().ConfigureAwait(false); - await PokemonService.UpdatePokemonListAsync().ConfigureAwait(false); + Client.Logger.LogInformation(EventId, "Initializing..."); + await SteamService.UpdateSteamAppListAsync(Program.Settings.Tokens.SteamToken).ConfigureAwait(false); + await TeamFortressService.UpdateTf2SchemaAsync(Program.Settings.Tokens.SteamToken).ConfigureAwait(false); + await NintendoService.UpdatePokemonListAsync().ConfigureAwait(false); + + // Send a notification to load Lavalink + Client.Logger.LogInformation(EventId, "Make sure Lavalink is running!"); // Set the initial activity and connect the bot to Discord var act = new DiscordActivity("Night of Fire", ActivityType.ListeningTo); @@ -144,7 +149,8 @@ public async Task StopAsync() private static Task Client_Ready(DiscordClient sender, ReadyEventArgs e) { - sender.Logger.LogInformation(EventId, $"{SharedData.Name}, version: {SharedData.Version}"); + var settings = Program.Settings; + sender.Logger.LogInformation(EventId, $"{settings.Name}, version: {settings.Version}"); return Task.CompletedTask; } @@ -154,25 +160,25 @@ private Task Client_GuildAvailable(DiscordClient sender, GuildCreateEventArgs e) return Task.CompletedTask; } - private static Task Client_ClientErrored(DiscordClient sender, ClientErrorEventArgs e) + private static Task Client_ClientError(DiscordClient sender, ClientErrorEventArgs e) { sender.Logger.LogError(EventId, $"[{e.Exception.GetType()}] Client Exception. {e.Exception.Message}"); return Task.CompletedTask; } - private Task Client_SocketErrored(DiscordClient sender, SocketErrorEventArgs e) + private Task Client_SocketError(DiscordClient sender, SocketErrorEventArgs e) { var ex = e.Exception; while (ex is AggregateException) ex = ex.InnerException; - sender.Logger.LogCritical(EventId, $"Socket threw an exception {ex.GetType()}: {ex.Message}"); + sender.Logger.LogCritical(EventId, $"Socket threw an exception {ex?.GetType()}: {ex?.Message}"); return Task.CompletedTask; } private async Task Client_VoiceStateUpdated(DiscordClient sender, VoiceStateUpdateEventArgs e) { - var musicData = await Services.GetService().GetOrCreateDataAsync(e.Guild); + var musicData = await Services.GetService()?.GetOrCreateDataAsync(e.Guild); if (e.After.Channel == null && e.User == Client.CurrentUser) { await musicData.StopAsync(); @@ -204,14 +210,14 @@ private static Task Command_Executed(CommandsNextExtension sender, CommandExecut return Task.CompletedTask; } - private static async Task Command_Errored(CommandsNextExtension sender, CommandErrorEventArgs e) + private static async Task Command_Error(CommandsNextExtension sender, CommandErrorEventArgs e) { await Exceptions.Process(e, EventId); } private static Task PrefixResolverAsync(DiscordMessage m) { - return Task.FromResult(m.GetStringPrefixLength(SharedData.Tokens.CommandPrefix)); + return Task.FromResult(m.GetStringPrefixLength(Program.Settings.Prefix)); } } } \ No newline at end of file diff --git a/src/FlawBOT/FlawBOT.csproj b/src/FlawBOT/FlawBOT.csproj index d935d466..f32810ff 100644 --- a/src/FlawBOT/FlawBOT.csproj +++ b/src/FlawBOT/FlawBOT.csproj @@ -6,11 +6,11 @@ favicon.ico FlawBOT.Program false - 3.0.0 + 3.1.0 9.0 - 3.0.0.0 - 3.0.0.0 + 3.1.0.0 + 3.1.0.0 FlawBOT FlawBOT @@ -25,7 +25,7 @@ false - x86 + AnyCPU @@ -47,23 +47,23 @@ - - - - - - + + + + + + + - + - + - - - + + diff --git a/src/FlawBOT/Lavalink.jar b/src/FlawBOT/Lavalink.jar index 74922a7d..ac4fc9cb 100644 Binary files a/src/FlawBOT/Lavalink.jar and b/src/FlawBOT/Lavalink.jar differ diff --git a/src/FlawBOT/Models/TokenData.cs b/src/FlawBOT/Models/TokenData.cs deleted file mode 100644 index aebd7eaf..00000000 --- a/src/FlawBOT/Models/TokenData.cs +++ /dev/null @@ -1,38 +0,0 @@ -using Newtonsoft.Json; - -namespace FlawBOT.Models -{ - public class TokenData - { - [JsonProperty("prefix")] public string CommandPrefix { get; set; } - - [JsonProperty("discord")] public string DiscordToken { get; set; } - - [JsonProperty("steam", NullValueHandling = NullValueHandling.Ignore)] - public string SteamToken { get; set; } - - [JsonProperty("imgur", NullValueHandling = NullValueHandling.Ignore)] - public string ImgurToken { get; set; } - - [JsonProperty("omdb", NullValueHandling = NullValueHandling.Ignore)] - public string OmdbToken { get; set; } - - [JsonProperty("twitch", NullValueHandling = NullValueHandling.Ignore)] - public string TwitchToken { get; set; } - - [JsonProperty("nasa", NullValueHandling = NullValueHandling.Ignore)] - public string NasaToken { get; set; } - - [JsonProperty("teamworktf", NullValueHandling = NullValueHandling.Ignore)] - public string TeamworkToken { get; set; } - - [JsonProperty("news", NullValueHandling = NullValueHandling.Ignore)] - public string NewsToken { get; set; } - - [JsonProperty("weather", NullValueHandling = NullValueHandling.Ignore)] - public string WeatherToken { get; set; } - - [JsonProperty("youtube", NullValueHandling = NullValueHandling.Ignore)] - public string YouTubeToken { get; set; } - } -} \ No newline at end of file diff --git a/src/FlawBOT/Models/WorldData.cs b/src/FlawBOT/Models/WorldData.cs index 209c599c..20195981 100644 --- a/src/FlawBOT/Models/WorldData.cs +++ b/src/FlawBOT/Models/WorldData.cs @@ -133,7 +133,7 @@ public class Current public int Pressure { get; set; } [JsonProperty("precip", NullValueHandling = NullValueHandling.Ignore)] - public int Precipitation { get; set; } + public double Precipitation { get; set; } [JsonProperty("humidity", NullValueHandling = NullValueHandling.Ignore)] public int Humidity { get; set; } diff --git a/src/FlawBOT/Modules/Bot/BotModule.cs b/src/FlawBOT/Modules/Bot/BotModule.cs index 24675c69..744eb958 100644 --- a/src/FlawBOT/Modules/Bot/BotModule.cs +++ b/src/FlawBOT/Modules/Bot/BotModule.cs @@ -4,14 +4,14 @@ using DSharpPlus.CommandsNext; using DSharpPlus.CommandsNext.Attributes; using DSharpPlus.Entities; -using FlawBOT.Common; using FlawBOT.Properties; using FlawBOT.Services; namespace FlawBOT.Modules { [Group("bot")] - [Description("Basic commands for interacting with FlawBOT")] + [Aliases("flaw")] + [Description("Basic commands for interacting with FlawBOT.")] [Cooldown(3, 5, CooldownBucketType.Channel)] public class BotModule : BaseCommandModule { @@ -19,21 +19,22 @@ public class BotModule : BaseCommandModule [Command("info")] [Aliases("about")] - [Description("Retrieve FlawBOT information")] + [Description("Retrieve information about FlawBOT.")] public async Task BotInfo(CommandContext ctx) { - var uptime = DateTime.Now - SharedData.ProcessStarted; + var settings = Program.Settings; + var uptime = DateTime.Now - settings.ProcessStarted; var output = new DiscordEmbedBuilder() - .WithTitle(SharedData.Name) + .WithTitle(settings.Name) .WithDescription( "A multipurpose Discord bot written in C# with [DSharpPlus](https://github.com/DSharpPlus/DSharpPlus/).") .AddField(":clock1: Uptime", $"{(int) uptime.TotalDays:00} days {uptime.Hours:00}:{uptime.Minutes:00}:{uptime.Seconds:00}", true) .AddField(":link: Links", - $"[Commands]({SharedData.GitHubLink}wiki) **|** [GitHub]({SharedData.GitHubLink})", true) - .WithFooter($"Thank you for using {SharedData.Name} (v{SharedData.Version})") - .WithUrl(SharedData.GitHubLink) - .WithColor(SharedData.DefaultColor); + $"[Commands]({settings.DocsLink}) **|** [GitHub]({settings.GitHubLink})", true) + .WithFooter($"Thank you for using {settings.Name} (v{settings.Version})") + .WithUrl(settings.GitHubLink) + .WithColor(settings.DefaultColor); await ctx.RespondAsync(output.Build()).ConfigureAwait(false); } @@ -42,11 +43,12 @@ public async Task BotInfo(CommandContext ctx) #region COMMAND_LEAVE [Command("leave")] - [Description("Make FlawBOT leave the current server")] + [Description("Make FlawBOT leave the server.")] [RequireUserPermissions(Permissions.Administrator)] public async Task LeaveServer(CommandContext ctx) { - await ctx.RespondAsync($"Are you sure you want {SharedData.Name} to leave the server?") + var settings = Program.Settings; + await ctx.RespondAsync($"Are you sure you want {settings.Name} to leave the server?") .ConfigureAwait(false); var message = await ctx .RespondAsync(Resources.INFO_RESPOND) @@ -59,7 +61,7 @@ await message.ModifyAsync($"~~{message.Content}~~ {Resources.INFO_REQ_TIMEOUT}") return; } - await BotServices.SendResponseAsync(ctx, $"Thank you for using {SharedData.Name}").ConfigureAwait(false); + await BotServices.SendResponseAsync(ctx, $"Thank you for using {settings.Name}").ConfigureAwait(false); await ctx.Guild.LeaveAsync().ConfigureAwait(false); } @@ -69,7 +71,7 @@ await message.ModifyAsync($"~~{message.Content}~~ {Resources.INFO_REQ_TIMEOUT}") [Command("ping")] [Aliases("pong")] - [Description("Ping the FlawBOT client")] + [Description("Ping the FlawBOT client.")] public async Task PingBot(CommandContext ctx) { await BotServices.SendResponseAsync(ctx, $":ping_pong: Pong! Ping: **{ctx.Client.Ping}**ms") @@ -83,9 +85,9 @@ await BotServices.SendResponseAsync(ctx, $":ping_pong: Pong! Ping: **{ctx.Client [Hidden] [Command("report")] [Aliases("issue")] - [Description("Report a problem with FlawBOT to the developer. Please do not abuse.")] + [Description("Report a problem with FlawBOT to the developer.")] public async Task ReportIssue(CommandContext ctx, - [Description("Detailed description of the issue")] [RemainingText] + [Description("Detailed description of the issue.")] [RemainingText] string report) { if (string.IsNullOrWhiteSpace(report) || report.Length < 50) @@ -106,6 +108,7 @@ await message.ModifyAsync($"~~{message.Content}~~ {Resources.INFO_REQ_TIMEOUT}") } else { + var settings = Program.Settings; var dm = await ctx.Member.CreateDmChannelAsync().ConfigureAwait(false); var output = new DiscordEmbedBuilder() .WithAuthor(ctx.Guild.Owner.Username + "#" + ctx.Guild.Owner.Discriminator, @@ -115,8 +118,8 @@ await message.ModifyAsync($"~~{message.Content}~~ {Resources.INFO_REQ_TIMEOUT}") .AddField("Server", ctx.Guild.Name + $" (ID: {ctx.Guild.Id})") .AddField("Owner", ctx.Guild.Owner.Username + "#" + ctx.Guild.Owner.Discriminator) .AddField("Confirm", - $"[Click here to add this issue to GitHub]({SharedData.GitHubLink}/issues/new)") - .WithColor(SharedData.DefaultColor); + $"[Click here to add this issue to GitHub]({settings.GitHubLink}/issues/new)") + .WithColor(settings.DefaultColor); await dm.SendMessageAsync(output.Build()).ConfigureAwait(false); await ctx.RespondAsync("Thank You! Your report has been submitted.").ConfigureAwait(false); } @@ -127,14 +130,14 @@ await message.ModifyAsync($"~~{message.Content}~~ {Resources.INFO_REQ_TIMEOUT}") #region COMMAND_UPTIME [Command("uptime")] - [Aliases("time")] [Description("Retrieve the FlawBOT uptime")] public async Task Uptime(CommandContext ctx) { - var uptime = DateTime.Now - SharedData.ProcessStarted; + var settings = Program.Settings; + var uptime = DateTime.Now - settings.ProcessStarted; var days = uptime.Days > 0 ? $"({uptime.Days:00} days)" : string.Empty; await BotServices.SendResponseAsync(ctx, - $":clock1: {SharedData.Name} has been online for {uptime.Hours:00}:{uptime.Minutes:00}:{uptime.Seconds} {days}") + $":clock1: {settings.Name} has been online for {uptime.Hours:00}:{uptime.Minutes:00}:{uptime.Seconds} {days}") .ConfigureAwait(false); } @@ -148,9 +151,9 @@ await BotServices.SendResponseAsync(ctx, [Hidden] [Command("activity")] [Aliases("setactivity")] - [Description("Set FlawBOT's activity")] + [Description("Set FlawBOT's activity.")] public async Task SetBotActivity(CommandContext ctx, - [Description("Name of the activity")] [RemainingText] + [Description("Name of the activity.")] [RemainingText] string activity) { if (string.IsNullOrWhiteSpace(activity)) @@ -161,7 +164,7 @@ public async Task SetBotActivity(CommandContext ctx, var game = new DiscordActivity(activity); await ctx.Client.UpdateStatusAsync(game).ConfigureAwait(false); - await ctx.RespondAsync($"{SharedData.Name} activity has been changed to Playing {game.Name}") + await ctx.RespondAsync($"{Program.Settings.Name} activity has been changed to Playing {game.Name}") .ConfigureAwait(false); } @@ -173,15 +176,15 @@ await ctx.RespondAsync($"{SharedData.Name} activity has been changed to Playing [Hidden] [Command("avatar")] [Aliases("setavatar", "pfp", "photo")] - [Description("Set FlawBOT's avatar")] + [Description("Set FlawBOT's avatar.")] public async Task SetBotAvatar(CommandContext ctx, - [Description("Image URL. Must be in jpg, png or img format.")] + [Description("Image URL. Must be in JPG, PNG or IMG format.")] string query) { var stream = BotServices.CheckImageInput(ctx, query).Result; if (stream.Length <= 0) return; await ctx.Client.UpdateCurrentUserAsync(avatar: stream).ConfigureAwait(false); - await ctx.RespondAsync($"{SharedData.Name} avatar has been updated!").ConfigureAwait(false); + await ctx.RespondAsync($"{Program.Settings.Name} avatar has been updated!").ConfigureAwait(false); } #endregion COMMAND_AVATAR @@ -192,30 +195,31 @@ public async Task SetBotAvatar(CommandContext ctx, [Hidden] [Command("status")] [Aliases("setstatus", "state")] - [Description("Set FlawBOT's status")] + [Description("Set FlawBOT's status.")] public async Task SetBotStatus(CommandContext ctx, [Description("Activity Status. Online, Idle, DND or Offline")] [RemainingText] string status) { + var settings = Program.Settings; status ??= "ONLINE"; switch (status.Trim().ToUpperInvariant()) { case "OFF": case "OFFLINE": await ctx.Client.UpdateStatusAsync(userStatus: UserStatus.Offline).ConfigureAwait(false); - await BotServices.SendResponseAsync(ctx, $"{SharedData.Name} status has been changed to Offline") + await BotServices.SendResponseAsync(ctx, $"{settings.Name} status has been changed to Offline") .ConfigureAwait(false); break; case "INVISIBLE": await ctx.Client.UpdateStatusAsync(userStatus: UserStatus.Invisible).ConfigureAwait(false); - await BotServices.SendResponseAsync(ctx, $"{SharedData.Name} status has been changed to Invisible") + await BotServices.SendResponseAsync(ctx, $"{settings.Name} status has been changed to Invisible") .ConfigureAwait(false); break; case "IDLE": await ctx.Client.UpdateStatusAsync(userStatus: UserStatus.Idle).ConfigureAwait(false); - await BotServices.SendResponseAsync(ctx, $"{SharedData.Name} status has been changed to Idle") + await BotServices.SendResponseAsync(ctx, $"{settings.Name} status has been changed to Idle") .ConfigureAwait(false); break; @@ -223,13 +227,13 @@ await BotServices.SendResponseAsync(ctx, $"{SharedData.Name} status has been cha case "DO NOT DISTURB": await ctx.Client.UpdateStatusAsync(userStatus: UserStatus.DoNotDisturb).ConfigureAwait(false); await BotServices - .SendResponseAsync(ctx, $"{SharedData.Name} status has been changed to Do Not Disturb") + .SendResponseAsync(ctx, $"{settings.Name} status has been changed to Do Not Disturb") .ConfigureAwait(false); break; default: await ctx.Client.UpdateStatusAsync(userStatus: UserStatus.Online).ConfigureAwait(false); - await BotServices.SendResponseAsync(ctx, $"{SharedData.Name} status has been changed to Online") + await BotServices.SendResponseAsync(ctx, $"{settings.Name} status has been changed to Online") .ConfigureAwait(false); break; } @@ -243,13 +247,13 @@ await BotServices.SendResponseAsync(ctx, $"{SharedData.Name} status has been cha [Hidden] [Command("username")] [Aliases("setusername", "name", "setname", "nickname", "nick")] - [Description("Set FlawBOT's username")] + [Description("Set FlawBOT's username.")] public async Task SetBotUsername(CommandContext ctx, - [Description("New bot username")] [RemainingText] + [Description("New nickname for FlawBOT.")] [RemainingText] string name) { var oldName = ctx.Client.CurrentUser.Username; - var newName = string.IsNullOrWhiteSpace(name) ? SharedData.Name : name; + var newName = string.IsNullOrWhiteSpace(name) ? Program.Settings.Name : name; await ctx.Client.UpdateCurrentUserAsync(newName).ConfigureAwait(false); await BotServices.SendResponseAsync(ctx, $"{oldName}'s username has been changed to {newName}") .ConfigureAwait(false); diff --git a/src/FlawBOT/Modules/Bot/MusicModule.cs b/src/FlawBOT/Modules/Bot/MusicModule.cs index e59446d7..c7b16261 100644 --- a/src/FlawBOT/Modules/Bot/MusicModule.cs +++ b/src/FlawBOT/Modules/Bot/MusicModule.cs @@ -65,7 +65,6 @@ public async Task ResumeAsync(CommandContext ctx) #region COMMAND_VOLUME [Command("volume")] - [Aliases("v")] [Description("Set audio playback volume.")] public async Task SetVolume(CommandContext ctx, [Description("Audio volume. Can be set to 0-150 (default 100).")] @@ -150,10 +149,9 @@ public override async Task BeforeExecutionAsync(CommandContext ctx) [Priority(1)] [Command("play")] - [Aliases("p")] [Description("Play audio from provided URL or search by specified query.")] public async Task PlaySong(CommandContext ctx, - [Description("URL from which to play audio")] + [Description("URL from which to play audio.")] Uri uri) { var trackLoad = await Service.GetTracksAsync(uri); diff --git a/src/FlawBOT/Modules/Games/PokemonModule.cs b/src/FlawBOT/Modules/Games/NintendoModule.cs similarity index 51% rename from src/FlawBOT/Modules/Games/PokemonModule.cs rename to src/FlawBOT/Modules/Games/NintendoModule.cs index b7ffbc5f..ee1f7b89 100644 --- a/src/FlawBOT/Modules/Games/PokemonModule.cs +++ b/src/FlawBOT/Modules/Games/NintendoModule.cs @@ -11,8 +11,55 @@ namespace FlawBOT.Modules { [Cooldown(3, 5, CooldownBucketType.Channel)] - public class PokemonModule : BaseCommandModule + public class NintendoModule : BaseCommandModule { + #region COMMAND_AMIIBO + + [Command("amiibo")] + [Aliases("amib")] + [Description("Retrieve information about an Amiibo figurine.")] + public async Task GetAmiibo(CommandContext ctx, + [Description("Name of the Amiibo figurine.")] [RemainingText] + string query) + { + if (string.IsNullOrWhiteSpace(query)) return; + await ctx.TriggerTypingAsync(); + var results = await NintendoService.GetAmiiboDataAsync(query).ConfigureAwait(false); + if (results is null) + { + await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_COMMON, ResponseType.Missing) + .ConfigureAwait(false); + return; + } + + foreach (var amiibo in results.Amiibo) + { + var output = new DiscordEmbedBuilder() + .WithTitle(amiibo.Name) + .AddField("Amiibo Series", amiibo.AmiiboSeries, true) + .AddField("Game Series", amiibo.GameSeries, true) + .AddField(":flag_us: Release:", amiibo.ReleaseDate.American, true) + .AddField(":flag_jp: Release:", amiibo.ReleaseDate.Japanese, true) + .AddField(":flag_eu: Release:", amiibo.ReleaseDate.European, true) + .AddField(":flag_au: Release:", amiibo.ReleaseDate.Australian, true) + .WithImageUrl(amiibo.Image) + .WithFooter(!amiibo.Equals(results.Amiibo.Last()) + ? "Type 'next' within 10 seconds for the next amiibo." + : "This is the last found amiibo on the list.") + .WithColor(new DiscordColor("#E70009")); + var message = await ctx.RespondAsync(output.Build()).ConfigureAwait(false); + + if (results.Amiibo.Count == 1) continue; + var interactivity = await BotServices.GetUserInteractivity(ctx, "next", 10).ConfigureAwait(false); + if (interactivity.Result is null) break; + await BotServices.RemoveMessage(interactivity.Result).ConfigureAwait(false); + if (!amiibo.Equals(results.Amiibo.Last())) + await BotServices.RemoveMessage(message).ConfigureAwait(false); + } + } + + #endregion COMMAND_AMIIBO + #region COMMAND_POKEMON [Command("pokemon")] @@ -22,7 +69,8 @@ public async Task Pokemon(CommandContext ctx, [Description("Name of the Pokémon")] [RemainingText] string query = "") { - var results = await PokemonService.GetPokemonCardsAsync(query).ConfigureAwait(false); + await ctx.TriggerTypingAsync(); + var results = await NintendoService.GetPokemonCardsAsync(query).ConfigureAwait(false); if (results.Cards.Count == 0) { await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_COMMON, ResponseType.Missing) @@ -32,7 +80,7 @@ await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_COMMON, ResponseTyp foreach (var dex in results.Cards) { - var card = PokemonService.GetExactPokemon(dex.Id); + var card = NintendoService.GetExactPokemon(dex.Id); var output = new DiscordEmbedBuilder() .WithTitle(card.Name + $" (#{card.NationalPokedexNumber})") .AddField("Series", card.Series ?? "Unknown", true) @@ -41,7 +89,7 @@ await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_COMMON, ResponseTyp .AddField("Ability", card.Ability != null ? card.Ability.Name : "Unknown", true) .WithImageUrl(card.ImageUrlHiRes ?? card.ImageUrl) .WithFooter(!string.Equals(card.Id, results.Cards.Last().Id) - ? "Type 'next' within 10 seconds for the next Pokémon" + ? "Type 'next' within 10 seconds for the next Pokémon." : "This is the last found Pokémon on the list.") .WithColor(DiscordColor.Gold); diff --git a/src/FlawBOT/Modules/Games/SpeedrunModule.cs b/src/FlawBOT/Modules/Games/SpeedrunModule.cs index 504c5330..0b9fb492 100644 --- a/src/FlawBOT/Modules/Games/SpeedrunModule.cs +++ b/src/FlawBOT/Modules/Games/SpeedrunModule.cs @@ -20,10 +20,11 @@ public class SpeedrunModule : BaseCommandModule [Aliases("game", "run")] [Description("Retrieve a game from Speedrun.com")] public async Task Speedrun(CommandContext ctx, - [Description("Game to search on Speedrun.com")] [RemainingText] + [Description("Game to find on Speedrun.com")] [RemainingText] string query) { if (string.IsNullOrWhiteSpace(query)) return; + await ctx.TriggerTypingAsync(); var results = SpeedrunService.GetSpeedrunGameAsync(query).Result; if (results is null || results.Data.Count == 0) { @@ -57,7 +58,7 @@ await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_COMMON, ResponseTyp if (categories != null || categories.Data.Count > 0) foreach (var x in categories.Data) category.Append($"[{x.Name}]({x.Weblink}) **|** "); - output.AddField("Categories", category.ToString() ?? "Unknown"); + output.AddField("Categories", category.ToString()); await ctx.RespondAsync(output.Build()).ConfigureAwait(false); if (results.Data.Count == 1) continue; diff --git a/src/FlawBOT/Modules/Games/SteamModule.cs b/src/FlawBOT/Modules/Games/SteamModule.cs index dbdbbed8..ea67258c 100644 --- a/src/FlawBOT/Modules/Games/SteamModule.cs +++ b/src/FlawBOT/Modules/Games/SteamModule.cs @@ -15,20 +15,43 @@ namespace FlawBOT.Modules { [Group("steam")] - [Description("Commands finding Steam games and users")] + [Description("Commands finding Steam games and users.")] [Cooldown(3, 5, CooldownBucketType.Channel)] public class SteamModule : BaseCommandModule { + #region COMMAND_CONNECT + + [Command("connect")] + [Aliases("link")] + [Description("Format a game connection string into a link.")] + public async Task SteamLink(CommandContext ctx, + [Description("Connection string (ex. IP:PORT).")] [RemainingText] + string link) + { + await ctx.TriggerTypingAsync(); + var regex = new Regex(@"\s*(?'ip'\S+)\s*", RegexOptions.Compiled).Match(link); + if (regex.Success) + await ctx.RespondAsync( + string.Format($"steam://connect/{regex.Groups["ip"].Value}/{regex.Groups["pw"].Value}")) + .ConfigureAwait(false); + else + await BotServices.SendResponseAsync(ctx, Resources.ERR_INVALID_IP_GAME, ResponseType.Warning) + .ConfigureAwait(false); + } + + #endregion COMMAND_CONNECT + #region COMMAND_GAME [Command("game")] - [Description("Retrieve Steam game information")] + [Description("Retrieve information on a Steam game.")] public async Task SteamGame(CommandContext ctx, - [Description("Game to find on Steam")] [RemainingText] + [Description("Game to find on Steam.")] [RemainingText] string query = "Team Fortress 2") { try { + await ctx.TriggerTypingAsync(); var app = SteamService.GetSteamAppAsync(query).Result; if (app is null) { @@ -73,13 +96,14 @@ await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_COMMON, ResponseTyp [Command("user")] [Aliases("player")] - [Description("Retrieve Steam user information")] + [Description("Retrieve information on a Steam user.")] public async Task SteamUser(CommandContext ctx, - [Description("User to find on Steam")] [RemainingText] + [Description("User to find on Steam.")] [RemainingText] string query) { if (string.IsNullOrWhiteSpace(query)) return; - var profile = SteamService.GetSteamProfileAsync(query).Result; + await ctx.TriggerTypingAsync(); + var profile = SteamService.GetSteamProfileAsync(Program.Settings.Tokens.SteamToken, query).Result; if (profile is null) { await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_COMMON, ResponseType.Missing) @@ -117,26 +141,5 @@ await BotServices.SendResponseAsync(ctx, "This profile is private...", ResponseT } #endregion COMMAND_USER - - #region COMMAND_CONNECT - - [Command("connect")] - [Aliases("link")] - [Description("Format a game connection string into a link")] - public async Task SteamLink(CommandContext ctx, - [Description("Connection string")] [RemainingText] - string link) - { - var regex = new Regex(@"\s*(?'ip'\S+)\s*", RegexOptions.Compiled).Match(link); - if (regex.Success) - await ctx.RespondAsync( - string.Format($"steam://connect/{regex.Groups["ip"].Value}/{regex.Groups["pw"].Value}")) - .ConfigureAwait(false); - else - await BotServices.SendResponseAsync(ctx, Resources.ERR_INVALID_IP_GAME, ResponseType.Warning) - .ConfigureAwait(false); - } - - #endregion COMMAND_CONNECT } } \ No newline at end of file diff --git a/src/FlawBOT/Modules/Games/TeamFortressModule.cs b/src/FlawBOT/Modules/Games/TeamFortressModule.cs index f23fdc60..28587463 100644 --- a/src/FlawBOT/Modules/Games/TeamFortressModule.cs +++ b/src/FlawBOT/Modules/Games/TeamFortressModule.cs @@ -15,7 +15,7 @@ namespace FlawBOT.Modules { [Group("tf2")] - [Description("Commands related to Team Fortress 2")] + [Description("Commands related to Team Fortress 2.")] [Cooldown(3, 5, CooldownBucketType.Channel)] public class TeamFortressModule : BaseCommandModule { @@ -23,11 +23,12 @@ public class TeamFortressModule : BaseCommandModule [Command("item")] [Aliases("schema", "hat")] - [Description("Retrieve an item from the latest TF2 item schema")] + [Description("Retrieve an item from the latest TF2 item schema.")] public async Task Tf2Schema(CommandContext ctx, [Description("Item to find in the TF2 schema")] [RemainingText] string query = "The Scattergun") { + await ctx.TriggerTypingAsync(); var item = TeamFortressService.GetSchemaItem(query); if (item is null) { @@ -76,7 +77,10 @@ public async Task Tf2Map(CommandContext ctx, string query) { if (string.IsNullOrWhiteSpace(query)) return; - var results = await TeamFortressService.GetMapStatsAsync(query.ToLowerInvariant()).ConfigureAwait(false); + await ctx.TriggerTypingAsync(); + var results = await TeamFortressService + .GetMapStatsAsync(Program.Settings.Tokens.TeamworkToken, query.ToLowerInvariant()) + .ConfigureAwait(false); if (results is null) { await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_COMMON, ResponseType.Missing) @@ -118,7 +122,8 @@ await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_COMMON, ResponseTyp if (results.GameModes.Count > 0) { - var desc = TeamFortressService.GetGameModeInfoAsync(results.GameModes.FirstOrDefault()).Result; + var desc = TeamFortressService.GetGameModeInfoAsync(Program.Settings.Tokens.TeamworkToken, + results.GameModes.FirstOrDefault()).Result; output.WithDescription(desc.Title + " - " + desc.Description); output.WithColor(new DiscordColor($"#{desc.Color}")); } @@ -131,12 +136,14 @@ await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_COMMON, ResponseTyp #region COMMAND_NEWS [Command("news")] - [Description("Retrieve the latest news article from teamwork.tf")] + [Description("Retrieve the latest news article from teamwork.tf.")] public async Task Tf2News(CommandContext ctx, [Description("Page number from which to retrieve the news")] int query = 0) { - var results = await TeamFortressService.GetNewsArticlesAsync(query).ConfigureAwait(false); + await ctx.TriggerTypingAsync(); + var results = await TeamFortressService.GetNewsArticlesAsync(Program.Settings.Tokens.TeamworkToken, query) + .ConfigureAwait(false); if (results is null || results.Count == 0) { await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_COMMON, ResponseType.Missing) @@ -147,8 +154,10 @@ await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_COMMON, ResponseTyp while (results.Count > 0) { var output = new DiscordEmbedBuilder() - .WithFooter("Type 'next' within 10 seconds for the next five posts.") - .WithColor(new DiscordColor("#E7B53B")); + .WithColor(new DiscordColor("#E7B53B")) + .WithFooter(results.Count - 5 >= 5 + ? "Type 'next' within 10 seconds for the next five posts." + : "These are all the latest posts at this time."); foreach (var result in results.Take(5)) { @@ -160,7 +169,7 @@ await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_COMMON, ResponseTyp var message = await ctx.RespondAsync("Latest news articles from teamwork.tf", output) .ConfigureAwait(false); - if (results.Count == 5) continue; + if (results.Count < 5) break; var interactivity = await BotServices.GetUserInteractivity(ctx, "next", 10).ConfigureAwait(false); if (interactivity.Result is null) break; await BotServices.RemoveMessage(interactivity.Result).ConfigureAwait(false); @@ -174,12 +183,13 @@ await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_COMMON, ResponseTyp [Command("creator")] [Aliases("creators", "youtuber")] - [Description("Retrieve a community creator profile from teamwork.tf")] + [Description("Retrieve a community creator profile from teamwork.tf.")] public async Task Tf2Creators(CommandContext ctx, - [Description("Name of the community creator to find")] [RemainingText] + [Description("Name of the community creator to find.")] [RemainingText] string query) { if (string.IsNullOrWhiteSpace(query)) return; + await ctx.TriggerTypingAsync(); var steamId = SteamService.GetSteamUserId(query).Result; if (steamId is null) { @@ -188,7 +198,8 @@ await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_COMMON, ResponseTyp return; } - var results = await TeamFortressService.GetContentCreatorAsync(steamId.Data).ConfigureAwait(false); + var results = await TeamFortressService + .GetContentCreatorAsync(Program.Settings.Tokens.TeamworkToken, steamId.Data).ConfigureAwait(false); if (results.Count == 0) { await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_COMMON, ResponseType.Missing) @@ -201,7 +212,7 @@ await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_COMMON, ResponseTyp var user = results.FirstOrDefault(); var output = new DiscordEmbedBuilder() .WithTitle(user?.Name) - .WithDescription("Main Class: " + user?.Main?.ToString().ToUpper()) + .WithDescription("Main Class: " + user?.Main?.ToString()?.ToUpper()) .WithThumbnail(user?.ThumbnailUrl) .WithUrl(user?.Link) .WithColor(new DiscordColor("#E7B53B")) @@ -240,13 +251,15 @@ await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_COMMON, ResponseTyp [Command("server")] [Aliases("servers")] - [Description("Retrieve a list of servers with given game-mode")] + [Description("Retrieve a list of servers with given game-mode.")] public async Task Tf2ServerByMode(CommandContext ctx, - [Description("Name of the game-mode, like payload")] [RemainingText] + [Description("Name of the game-mode, like payload.")] [RemainingText] string query) { if (string.IsNullOrWhiteSpace(query)) return; - var results = await TeamFortressService.GetServersByGameModeAsync(query.Trim().Replace(' ', '-')) + await ctx.TriggerTypingAsync(); + var results = await TeamFortressService + .GetServersByGameModeAsync(Program.Settings.Tokens.TeamworkToken, query.Trim().Replace(' ', '-')) .ConfigureAwait(false); if (results is null) { @@ -270,10 +283,11 @@ await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_COMMON, ResponseTyp .AddField("All Talk", server.HasAllTalk ? "Yes" : "No", true) .AddField("Current Map", server.MapName ?? "Unknown", true) .AddField("Next Map", server.MapNameNext ?? "Unknown", true) - .WithFooter("Type 'next' within 10 seconds for the next server") + .WithFooter("Type 'next' within 10 seconds for the next server.") .WithColor(new DiscordColor("#E7B53B")); - var thumbnailUrl = await TeamFortressService.GetMapThumbnailAsync(server.MapName).ConfigureAwait(false); + var thumbnailUrl = await TeamFortressService + .GetMapThumbnailAsync(Program.Settings.Tokens.TeamworkToken, server.MapName).ConfigureAwait(false); output.WithImageUrl(thumbnailUrl.Name); var message = await ctx.RespondAsync(output.Build()).ConfigureAwait(false); @@ -294,6 +308,7 @@ public async Task Tf2ServerByIp(CommandContext ctx, [Description("Game server IP address, like 164.132.233.16")] [RemainingText] string ip) { + await ctx.TriggerTypingAsync(); if (string.IsNullOrWhiteSpace(ip) || !IPAddress.TryParse(ip, out var address)) { await BotServices.SendResponseAsync(ctx, Resources.ERR_INVALID_IP, ResponseType.Missing) @@ -302,7 +317,9 @@ await BotServices.SendResponseAsync(ctx, Resources.ERR_INVALID_IP, ResponseType. } await ctx.RespondAsync(string.Format(Resources.URL_Steam_Connect, address)).ConfigureAwait(false); - await ctx.RespondAsync(TeamFortressService.GetServerInfo(address.ToString())).ConfigureAwait(false); + await ctx.RespondAsync( + TeamFortressService.GetServerInfo(Program.Settings.Tokens.TeamworkToken, address.ToString())) + .ConfigureAwait(false); } [Command("list")] @@ -310,12 +327,14 @@ await BotServices.SendResponseAsync(ctx, Resources.ERR_INVALID_IP, ResponseType. [Description("Retrieve a curated list of servers")] public async Task Tf2ServerList(CommandContext ctx) { - var results = await TeamFortressService.GetCustomServerListsAsync().ConfigureAwait(false); + await ctx.TriggerTypingAsync(); + var results = await TeamFortressService.GetCustomServerListsAsync(Program.Settings.Tokens.TeamworkToken) + .ConfigureAwait(false); results = results.OrderBy(_ => new Random().Next()).ToList(); while (results.Count > 0) { var output = new DiscordEmbedBuilder() - .WithFooter("Type 'next' within 10 seconds for the next set of server lists") + .WithFooter("Type 'next' within 10 seconds for the next set of server lists.") .WithColor(new DiscordColor("#E7B53B")); foreach (var list in results.Take(4)) diff --git a/src/FlawBOT/Modules/Misc/MathModule.cs b/src/FlawBOT/Modules/Misc/MathModule.cs index e18dde18..613a3016 100644 --- a/src/FlawBOT/Modules/Misc/MathModule.cs +++ b/src/FlawBOT/Modules/Misc/MathModule.cs @@ -16,11 +16,11 @@ public class MathModule : BaseCommandModule [Command("math")] [Aliases("calculate")] - [Description("Perform a basic math operation")] + [Description("Perform a basic math operation.")] public async Task Math(CommandContext ctx, - [Description("First operand")] double num1, - [Description("Operator")] string operation, - [Description("Second operand")] double num2) + [Description("First operand.")] double num1, + [Description("Operator.")] string operation, + [Description("Second operand.")] double num2) { try { @@ -52,7 +52,7 @@ await BotServices.SendResponseAsync(ctx, Resources.ERR_MATH_EQUATION, ResponseTy [Aliases("total")] [Description("Calculate the sum of all inputted values")] public async Task Sum(CommandContext ctx, - [Description("Numbers to sum up")] params int[] args) + [Description("Numbers to sum up.")] params int[] args) { var output = new DiscordEmbedBuilder() .WithDescription($":1234: The sum is {args.Sum():#,##0}") diff --git a/src/FlawBOT/Modules/Misc/MiscModule.cs b/src/FlawBOT/Modules/Misc/MiscModule.cs index 466ef308..fe9c9ec1 100644 --- a/src/FlawBOT/Modules/Misc/MiscModule.cs +++ b/src/FlawBOT/Modules/Misc/MiscModule.cs @@ -14,13 +14,13 @@ namespace FlawBOT.Modules [Cooldown(3, 5, CooldownBucketType.Channel)] public class MiscModule : BaseCommandModule { - #region COMMAND_8BALL + #region COMMAND_ASK [Command("ask")] [Aliases("8b", "8ball", "ball", "8")] - [Description("Ask an 8-ball a question")] + [Description("Ask an 8-ball a question.")] public Task EightBall(CommandContext ctx, - [Description("Question to ask the 8-Ball")] [RemainingText] + [Description("Question to ask the 8-ball.")] [RemainingText] string question = "") { if (string.IsNullOrWhiteSpace(question)) return Task.CompletedTask; @@ -30,15 +30,16 @@ public Task EightBall(CommandContext ctx, return ctx.RespondAsync(output.Build()); } - #endregion COMMAND_8BALL + #endregion COMMAND_ASK #region COMMAND_CAT [Command("cat")] [Aliases("meow", "catfact", "randomcat")] - [Description("Retrieve a random cat fact")] + [Description("Retrieve a random cat fact and picture.")] public async Task GetCat(CommandContext ctx) { + await ctx.TriggerTypingAsync(); var results = MiscService.GetCatFactAsync().Result; var output = new DiscordEmbedBuilder() .WithFooter($"Fact: {JObject.Parse(results)["fact"]}") @@ -57,14 +58,14 @@ public async Task GetCat(CommandContext ctx) [Command("coinflip")] [Aliases("coin", "flip")] - [Description("Flip a coin")] + [Description("Flip a coin.")] public Task CoinFlip(CommandContext ctx) { var random = new Random(); var output = new DiscordEmbedBuilder() .WithDescription(ctx.User.Username + " flipped a coin and got " + Formatter.Bold(Convert.ToBoolean(random.Next(0, 2)) ? "Heads" : "Tails")) - .WithColor(SharedData.DefaultColor); + .WithColor(Program.Settings.DefaultColor); return ctx.RespondAsync(output.Build()); } @@ -74,14 +75,14 @@ public Task CoinFlip(CommandContext ctx) [Command("diceroll")] [Aliases("dice", "roll", "rolldice", "die")] - [Description("Roll a six-sided die")] + [Description("Roll a six-sided die.")] public Task RollDice(CommandContext ctx) { var random = new Random(); var output = new DiscordEmbedBuilder() .WithDescription(ctx.User.Username + " rolled a die and got " + Formatter.Bold(random.Next(1, 7).ToString())) - .WithColor(SharedData.DefaultColor); + .WithColor(Program.Settings.DefaultColor); return ctx.RespondAsync(output.Build()); } @@ -89,11 +90,12 @@ public Task RollDice(CommandContext ctx) #region COMMAND_DOG - [Command("randomdog")] - [Aliases("woof", "dog", "bark")] + [Command("dog")] + [Aliases("woof", "bark", "randomdog")] [Description("Retrieve a random dog photo")] public async Task GetDog(CommandContext ctx) { + await ctx.TriggerTypingAsync(); var results = MiscService.GetDogPhotoAsync().Result; if (results.Status != "success") { @@ -114,9 +116,9 @@ await BotServices.SendResponseAsync(ctx, Resources.ERR_API_CONNECTION, ResponseT [Command("hello")] [Aliases("hi", "howdy")] - [Description("Welcome another user to the server")] + [Description("Say hello to another user to the server.")] public async Task Greet(CommandContext ctx, - [Description("User to say hello to")] [RemainingText] + [Description("User to say hello to.")] [RemainingText] DiscordMember member) { if (member is null) @@ -132,9 +134,9 @@ await ctx.RespondAsync($"Welcome {member.Mention} to {ctx.Guild.Name}. Enjoy you [Command("tts")] [Aliases("echo", "repeat", "say", "talk")] - [Description("Make FlawBOT repeat a message as text-to-speech")] + [Description("Make FlawBOT repeat a message as text-to-speech.")] public async Task Say(CommandContext ctx, - [Description("Message for the bot to repeat")] [RemainingText] + [Description("Message for FlawBOT to repeat.")] [RemainingText] string message) { if (string.IsNullOrWhiteSpace(message)) diff --git a/src/FlawBOT/Modules/Misc/PollModule.cs b/src/FlawBOT/Modules/Misc/PollModule.cs deleted file mode 100644 index 41dc4a65..00000000 --- a/src/FlawBOT/Modules/Misc/PollModule.cs +++ /dev/null @@ -1,62 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using DSharpPlus.CommandsNext; -using DSharpPlus.CommandsNext.Attributes; -using DSharpPlus.Entities; -using DSharpPlus.Interactivity.Enums; -using DSharpPlus.Interactivity.Extensions; -using FlawBOT.Common; -using FlawBOT.Properties; -using FlawBOT.Services; - -namespace FlawBOT.Modules -{ - [Cooldown(3, 5, CooldownBucketType.Channel)] - public class PollModule : BaseCommandModule - { - #region COMMAND_POLL - - [Command("poll")] - [Aliases("vote")] - [Description("Run a Yay or Nay poll in the current channel")] - public async Task Poll(CommandContext ctx, - [Description("Question to be polled")] [RemainingText] - string question) - { - if (string.IsNullOrWhiteSpace(question)) - { - await BotServices.SendResponseAsync(ctx, Resources.ERR_POLL_QUESTION, ResponseType.Warning) - .ConfigureAwait(false); - return; - } - - // Build the poll question, duration and options. - question = ctx.User.Mention + " asked: " + question; - var interactivity = ctx.Client.GetInteractivity(); - var pollOptions = new List - { - DiscordEmoji.FromName(ctx.Client, ":thumbsup:"), - DiscordEmoji.FromName(ctx.Client, ":thumbsdown:") - }; - var duration = new TimeSpan(0, 3, 10); - var message = await ctx - .RespondAsync(new DiscordEmbedBuilder() - .WithDescription(question + $"\nThis poll ends in {duration.Minutes} minutes.").Build()) - .ConfigureAwait(false); - var results = await interactivity.DoPollAsync(message, pollOptions, PollBehaviour.DeleteEmojis, duration) - .ConfigureAwait(false); - - // Removed the initial poll and return the calculated results - await BotServices.RemoveMessage(message).ConfigureAwait(false); - var output = new DiscordEmbedBuilder() - .WithDescription(question) - .WithFooter("The voting has ended."); - foreach (var vote in results) - output.AddField(vote.Emoji.Name, vote.Voted.Count.ToString(), true); - await ctx.RespondAsync(output.Build()).ConfigureAwait(false); - } - - #endregion COMMAND_POLL - } -} \ No newline at end of file diff --git a/src/FlawBOT/Modules/Search/AmiiboModule.cs b/src/FlawBOT/Modules/Search/AmiiboModule.cs deleted file mode 100644 index dee6be6b..00000000 --- a/src/FlawBOT/Modules/Search/AmiiboModule.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System.Linq; -using System.Threading.Tasks; -using DSharpPlus.CommandsNext; -using DSharpPlus.CommandsNext.Attributes; -using DSharpPlus.Entities; -using FlawBOT.Common; -using FlawBOT.Properties; -using FlawBOT.Services; - -namespace FlawBOT.Modules -{ - [Cooldown(3, 5, CooldownBucketType.Channel)] - public class AmiiboModule : BaseCommandModule - { - #region COMMAND_AMIIBO - - [Command("amiibo")] - [Aliases("amib")] - [Description("Retrieve Amiibo figurine information")] - public async Task GetAmiibo(CommandContext ctx, - [Description("Name of the Amiibo figurine")] [RemainingText] - string query) - { - if (string.IsNullOrWhiteSpace(query)) return; - var results = await AmiiboService.GetAmiiboDataAsync(query).ConfigureAwait(false); - if (results is null) - { - await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_COMMON, ResponseType.Missing) - .ConfigureAwait(false); - return; - } - - foreach (var amiibo in results.Amiibo) - { - var output = new DiscordEmbedBuilder() - .WithTitle(amiibo.Name) - .AddField("Amiibo Series", amiibo.AmiiboSeries, true) - .AddField("Game Series", amiibo.GameSeries, true) - .AddField(":flag_us: Release:", amiibo.ReleaseDate.American, true) - .AddField(":flag_jp: Release:", amiibo.ReleaseDate.Japanese, true) - .AddField(":flag_eu: Release:", amiibo.ReleaseDate.European, true) - .AddField(":flag_au: Release:", amiibo.ReleaseDate.Australian, true) - .WithImageUrl(amiibo.Image) - .WithFooter(!amiibo.Equals(results.Amiibo.Last()) - ? "Type 'next' within 10 seconds for the next amiibo" - : "This is the last found amiibo on the list.") - .WithColor(new DiscordColor("#E70009")); - var message = await ctx.RespondAsync(output.Build()).ConfigureAwait(false); - - if (results.Amiibo.Count == 1) continue; - var interactivity = await BotServices.GetUserInteractivity(ctx, "next", 10).ConfigureAwait(false); - if (interactivity.Result is null) break; - await BotServices.RemoveMessage(interactivity.Result).ConfigureAwait(false); - if (!amiibo.Equals(results.Amiibo.Last())) - await BotServices.RemoveMessage(message).ConfigureAwait(false); - } - } - - #endregion COMMAND_AMIIBO - } -} \ No newline at end of file diff --git a/src/FlawBOT/Modules/Search/DictionaryModule.cs b/src/FlawBOT/Modules/Search/DictionaryModule.cs index 68481da6..b3053a47 100644 --- a/src/FlawBOT/Modules/Search/DictionaryModule.cs +++ b/src/FlawBOT/Modules/Search/DictionaryModule.cs @@ -17,12 +17,13 @@ public class DictionaryModule : BaseCommandModule [Command("dictionary")] [Aliases("define", "def", "dic")] - [Description("Retrieve an Urban Dictionary definition of a word or phrase")] + [Description("Retrieve an Urban Dictionary definition for a word or phrase.")] public async Task UrbanDictionary(CommandContext ctx, - [Description("Query to pass to Urban Dictionary")] [RemainingText] + [Description("Word or phrase to find on Urban Dictionary.")] [RemainingText] string query) { if (string.IsNullOrWhiteSpace(query)) return; + await ctx.TriggerTypingAsync(); var results = await DictionaryService.GetDictionaryDefinitionAsync(query).ConfigureAwait(false); if (results.ResultType == "no_results" || results.List.Count == 0) { @@ -46,7 +47,7 @@ await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_COMMON, ResponseTyp .AddField(":thumbsdown:", definition.ThumbsDown.ToString(), true) .WithUrl(definition.Permalink) .WithFooter(!definition.Equals(results.List.Last()) - ? "Type 'next' within 10 seconds for the next definition" + ? "Type 'next' within 10 seconds for the next definition." : "This is the last found definition on the list.") .WithColor(new DiscordColor("#1F2439")); var message = await ctx.RespondAsync(output.Build()).ConfigureAwait(false); diff --git a/src/FlawBOT/Modules/Search/ImgurModule.cs b/src/FlawBOT/Modules/Search/ImgurModule.cs index d61c6a9e..362c39a1 100644 --- a/src/FlawBOT/Modules/Search/ImgurModule.cs +++ b/src/FlawBOT/Modules/Search/ImgurModule.cs @@ -17,12 +17,13 @@ public class ImgurModule : BaseCommandModule [Command("imgur")] [Aliases("image")] - [Description("Retrieve an image from Imgur")] + [Description("Retrieve an image from Imgur.")] public async Task Imgur(CommandContext ctx, - [Description("Search query to pass to Imgur")] [RemainingText] + [Description("Search query to pass to Imgur.")] [RemainingText] string query) { - var results = ImgurService.GetImgurGalleryAsync(query).Result; + await ctx.TriggerTypingAsync(); + var results = ImgurService.GetImgurGalleryAsync(Program.Settings.Tokens.ImgurToken, query).Result; var output = new DiscordEmbedBuilder().WithColor(new DiscordColor("#89C623")); switch (results) diff --git a/src/FlawBOT/Modules/Search/NASAModule.cs b/src/FlawBOT/Modules/Search/NASAModule.cs index f258397a..09888be6 100644 --- a/src/FlawBOT/Modules/Search/NASAModule.cs +++ b/src/FlawBOT/Modules/Search/NASAModule.cs @@ -15,10 +15,11 @@ public class NasaModule : BaseCommandModule [Command("nasa")] [Aliases("apod", "space")] - [Description("Retrieve NASA's Astronomy Picture of the Day")] + [Description("Retrieve NASA's Astronomy Picture of the Day.")] public async Task Nasa(CommandContext ctx) { - var results = await NasaService.GetNasaImageAsync().ConfigureAwait(false); + await ctx.TriggerTypingAsync(); + var results = await NasaService.GetNasaImageAsync(Program.Settings.Tokens.NasaToken).ConfigureAwait(false); if (results is null) { await BotServices.SendResponseAsync(ctx, Resources.ERR_API_CONNECTION, ResponseType.Missing) diff --git a/src/FlawBOT/Modules/Search/NewsModule.cs b/src/FlawBOT/Modules/Search/NewsModule.cs index 798881de..6deea7ce 100644 --- a/src/FlawBOT/Modules/Search/NewsModule.cs +++ b/src/FlawBOT/Modules/Search/NewsModule.cs @@ -16,12 +16,14 @@ public class NewsModule : BaseCommandModule #region COMMAND_NEWS [Command("news")] - [Description("Retrieve the latest news articles from NewsAPI.org")] + [Description("Retrieve the news articles on a topic from NewsAPI.org.")] public async Task News(CommandContext ctx, - [Description("Article topic to find on Google News")] [RemainingText] + [Description("Article topic to find on NewsAPI.org.")] [RemainingText] string query) { - var results = await NewsService.GetNewsDataAsync(query).ConfigureAwait(false); + await ctx.TriggerTypingAsync(); + var results = await NewsService.GetNewsDataAsync(Program.Settings.Tokens.NewsToken, query) + .ConfigureAwait(false); if (results.Status != "ok") { await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_COMMON, ResponseType.Missing) diff --git a/src/FlawBOT/Modules/Search/OMDBModule.cs b/src/FlawBOT/Modules/Search/OMDBModule.cs index a093c2dc..fd840da8 100644 --- a/src/FlawBOT/Modules/Search/OMDBModule.cs +++ b/src/FlawBOT/Modules/Search/OMDBModule.cs @@ -16,13 +16,15 @@ public class OmdbModule : BaseCommandModule [Command("omdb")] [Aliases("imdb", "movie")] - [Description("Retrieve a movie or TV show from OMDB")] + [Description("Find a movie or TV show from OMDB.")] public async Task Omdb(CommandContext ctx, - [Description("Movie or TV show to find on OMDB")] [RemainingText] + [Description("Movie or TV show to find on OMDB.")] [RemainingText] string query) { if (string.IsNullOrWhiteSpace(query)) return; - var results = OmdbService.GetMovieListAsync(query.Replace(" ", "+")).Result; + await ctx.TriggerTypingAsync(); + var results = OmdbService.GetMovieListAsync(Program.Settings.Tokens.OmdbToken, query.Replace(" ", "+")) + .Result; if (!results.Search.Any()) { await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_COMMON, ResponseType.Missing) @@ -32,7 +34,8 @@ await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_COMMON, ResponseTyp foreach (var title in results.Search) { - var movie = OmdbService.GetMovieDataAsync(title.Title.Replace(" ", "+")).Result; + var movie = OmdbService + .GetMovieDataAsync(Program.Settings.Tokens.OmdbToken, title.Title.Replace(" ", "+")).Result; var output = new DiscordEmbedBuilder() .WithTitle(movie.Title) .WithDescription(movie.Plot.Length < 500 ? movie.Plot : movie.Plot.Take(500) + "...") @@ -45,7 +48,7 @@ await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_COMMON, ResponseTyp .AddField("Directors", movie.Director) .AddField("Actors", movie.Actors) .WithFooter(!movie.Title.Equals(results.Search.Last().Title) - ? "Type 'next' within 10 seconds for the next movie" + ? "Type 'next' within 10 seconds for the next movie." : "This is the last found movie on OMDB.") .WithColor(DiscordColor.Goldenrod); if (movie.Poster != "N/A") output.WithImageUrl(movie.Poster); diff --git a/src/FlawBOT/Modules/Search/RedditModule.cs b/src/FlawBOT/Modules/Search/RedditModule.cs index 38484bbe..c2957142 100644 --- a/src/FlawBOT/Modules/Search/RedditModule.cs +++ b/src/FlawBOT/Modules/Search/RedditModule.cs @@ -14,33 +14,46 @@ namespace FlawBOT.Modules [Cooldown(3, 5, CooldownBucketType.Channel)] public class RedditModule : BaseCommandModule { - #region COMMAND_POST + #region COMMAND_HOT [Command("hot")] - [Description("Get hottest posts for a subreddit.")] + [Description("Get hottest posts from a given subreddit.")] public Task HotPost(CommandContext ctx, [Description("Subreddit.")] string query) { return RedditPost(ctx, query, RedditCategory.Hot); } + #endregion COMMAND_HOT + + #region COMMAND_NEW + [Command("new")] - [Description("Get newest posts for a subreddit.")] + [Description("Get newest posts from a given subreddit.")] [Aliases("newest", "latest")] public Task NewPost(CommandContext ctx, [Description("Subreddit.")] string query) { return RedditPost(ctx, query, RedditCategory.New); } + #endregion COMMAND_NEW + + #region COMMAND_TOP + [Command("top")] - [Description("Get top posts for a subreddit.")] + [Description("Get top posts from a given subreddit.")] public Task TopPost(CommandContext ctx, [Description("Subreddit.")] string query) { return RedditPost(ctx, query, RedditCategory.Top); } + #endregion COMMAND_TOP + + #region COMMAND_POST + private static async Task RedditPost(CommandContext ctx, string query, RedditCategory category) { if (string.IsNullOrWhiteSpace(query)) return; + await ctx.TriggerTypingAsync(); var results = RedditService.GetResults(query, category); if (results is null || results.Count == 0) { diff --git a/src/FlawBOT/Modules/Search/SimpsonsModule.cs b/src/FlawBOT/Modules/Search/SimpsonsModule.cs index f10fe42d..9863ffa6 100644 --- a/src/FlawBOT/Modules/Search/SimpsonsModule.cs +++ b/src/FlawBOT/Modules/Search/SimpsonsModule.cs @@ -14,7 +14,7 @@ public class SimpsonsModule : BaseCommandModule [Command("simpsons")] [Aliases("caramba")] - [Description("Retrieve a random Simpsons screenshot and episode")] + [Description("Retrieve a random Simpsons screenshot and episode.")] public async Task Simpsons(CommandContext ctx) { var results = await SimpsonsService.GetSimpsonsDataAsync(SimpsonsService.SiteRoot.Frinkiac) @@ -26,11 +26,11 @@ public async Task Simpsons(CommandContext ctx) #region COMMAND_SIMPSONS_GIF - [Command("simpsonsgif")] + [Command("frinkiac")] [Aliases("doh")] - [Description("Retrieve a random Simpsons gif")] + [Description("Retrieve a random Simpsons gif.")] public async Task SimpsonsGif(CommandContext ctx, - [Description("Inputting anything will add episode information")] [RemainingText] + [Description("Inputting anything will add episode information.")] [RemainingText] string input) { var output = await SimpsonsService.GetSimpsonsGifAsync(SimpsonsService.SiteRoot.Frinkiac) @@ -54,7 +54,7 @@ public async Task SimpsonsGif(CommandContext ctx, [Command("futurama")] [Aliases("bite")] - [Description("Retrieve a random Futurama screenshot and episode")] + [Description("Retrieve a random Futurama screenshot and episode.")] public async Task Futurama(CommandContext ctx) { var results = await SimpsonsService.GetSimpsonsDataAsync(SimpsonsService.SiteRoot.Morbotron) @@ -67,11 +67,11 @@ public async Task Futurama(CommandContext ctx) #region COMMAND_FUTURAMA_GIF - [Command("futuramagif")] + [Command("morbotron")] [Aliases("neat")] [Description("Retrieve a random Futurama gif")] public async Task FuturamaGif(CommandContext ctx, - [Description("Inputting anything will add episode information")] [RemainingText] + [Description("Inputting anything will add episode information.")] [RemainingText] string input) { var output = await SimpsonsService.GetSimpsonsGifAsync(SimpsonsService.SiteRoot.Morbotron) @@ -92,11 +92,10 @@ public async Task FuturamaGif(CommandContext ctx, #endregion COMMAND_FUTURAMA_GIF - #region COMMAND_RICKMORTY + #region COMMAND_RICK&MORTY [Command("rick")] - [Aliases("morty")] - [Description("Retrieve a random Rick and Morty screenshot and episode")] + [Description("Retrieve a random Rick and Morty screenshot and episode.")] public async Task Morty(CommandContext ctx) { var results = await SimpsonsService.GetSimpsonsDataAsync(SimpsonsService.SiteRoot.MasterOfAllScience) @@ -105,15 +104,14 @@ public async Task Morty(CommandContext ctx) await ctx.RespondAsync(results.Build()).ConfigureAwait(false); } - #endregion COMMAND_RICKMORTY + #endregion COMMAND_RICK&MORTY - #region COMMAND_RICKMORTY_GIF + #region COMMAND_RICK&MORTY_GIF - [Command("rickgif")] - [Aliases("mortygif")] - [Description("Retrieve a random Rick and Morty gif")] + [Command("morty")] + [Description("Retrieve a random Rick and Morty gif.")] public async Task MortyGif(CommandContext ctx, - [Description("Inputting anything will add episode information")] [RemainingText] + [Description("Inputting anything will add episode information.")] [RemainingText] string input) { var output = await SimpsonsService.GetSimpsonsGifAsync(SimpsonsService.SiteRoot.MasterOfAllScience) @@ -132,6 +130,6 @@ public async Task MortyGif(CommandContext ctx, await ctx.RespondAsync(output, results.Build()).ConfigureAwait(false); } - #endregion COMMAND_RICKMORTY_GIF + #endregion COMMAND_RICK&MORTY_GIF } } \ No newline at end of file diff --git a/src/FlawBOT/Modules/Search/TwitchModule.cs b/src/FlawBOT/Modules/Search/TwitchModule.cs index 605d685c..a48efcb3 100644 --- a/src/FlawBOT/Modules/Search/TwitchModule.cs +++ b/src/FlawBOT/Modules/Search/TwitchModule.cs @@ -16,13 +16,15 @@ public class TwitchModule : BaseCommandModule [Command("twitch")] [Aliases("stream")] - [Description("Retrieve Twitch stream information")] + [Description("Retrieve Twitch stream information.")] public async Task Twitch(CommandContext ctx, - [Description("Channel to find on Twitch")] [RemainingText] + [Description("Channel to find on Twitch.")] [RemainingText] string query) { if (string.IsNullOrWhiteSpace(query)) return; - var results = await TwitchService.GetTwitchDataAsync(query).ConfigureAwait(false); + await ctx.TriggerTypingAsync(); + var results = await TwitchService.GetTwitchDataAsync(Program.Settings.Tokens.TwitchToken, query) + .ConfigureAwait(false); if (results.Total == 0) { await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_TWITCH, ResponseType.Missing) @@ -43,7 +45,7 @@ await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_TWITCH, ResponseTyp .WithImageUrl(streamer.Preview.Large) .WithUrl(streamer.Channel.Url) .WithFooter(!streamer.Id.Equals(results.Streams.Last().Id) - ? "Type 'next' within 10 seconds for the next streamer" + ? "Type 'next' within 10 seconds for the next streamer." : "This is the last found streamer on the list.") .WithColor(new DiscordColor("#6441A5")); var message = await ctx.RespondAsync(output.Build()).ConfigureAwait(false); diff --git a/src/FlawBOT/Modules/Search/WeatherModule.cs b/src/FlawBOT/Modules/Search/WeatherModule.cs new file mode 100644 index 00000000..14a7b552 --- /dev/null +++ b/src/FlawBOT/Modules/Search/WeatherModule.cs @@ -0,0 +1,51 @@ +using System; +using System.Linq; +using System.Net; +using System.Threading.Tasks; +using DSharpPlus.CommandsNext; +using DSharpPlus.CommandsNext.Attributes; +using DSharpPlus.Entities; +using FlawBOT.Common; +using FlawBOT.Properties; +using FlawBOT.Services; + +namespace FlawBOT.Modules +{ + [Cooldown(3, 5, CooldownBucketType.Channel)] + public class WeatherModule : BaseCommandModule + { + #region COMMAND_WEATHER + + [Command("weather")] + [Aliases("time")] + [Description("Retrieve the time and weather for specified location.")] + public async Task Weather(CommandContext ctx, + [Description("Location to get time and weather data from.")] [RemainingText] + string query) + { + if (string.IsNullOrWhiteSpace(query)) return; + await ctx.TriggerTypingAsync(); + var results = await WeatherService.GetWeatherDataAsync(Program.Settings.Tokens.WeatherToken, query) + .ConfigureAwait(false); + if (results is null) + { + await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_LOCATION, ResponseType.Missing) + .ConfigureAwait(false); + return; + } + + Func format = WeatherService.CelsiusToFahrenheit; + var output = new DiscordEmbedBuilder() + .WithDescription("Weather in " + results.Location.Name + ", " + results.Location.Country) + .AddField(":partly_sunny: Currently", results.Current.Descriptions.FirstOrDefault(), true) + .AddField(":thermometer: Temperature", + $"{results.Current.Temperature:F1}°C / {format(results.Current.Temperature):F1}°F", true) + .AddField(":droplet: Humidity", $"{results.Current.Humidity}%", true) + .AddField(":clock1: Local Time", results.Location.LocalTime, true) + .WithColor(Program.Settings.DefaultColor); + await ctx.RespondAsync(output.Build()).ConfigureAwait(false); + } + + #endregion COMMAND_WEATHER + } +} \ No newline at end of file diff --git a/src/FlawBOT/Modules/Search/WikipediaModule.cs b/src/FlawBOT/Modules/Search/WikipediaModule.cs index 83fe02e1..e5e7af0f 100644 --- a/src/FlawBOT/Modules/Search/WikipediaModule.cs +++ b/src/FlawBOT/Modules/Search/WikipediaModule.cs @@ -1,4 +1,5 @@ -using System.Text.RegularExpressions; +using System.Linq; +using System.Text.RegularExpressions; using System.Threading.Tasks; using DSharpPlus; using DSharpPlus.CommandsNext; @@ -17,36 +18,57 @@ public class WikipediaModule : BaseCommandModule [Command("wiki")] [Aliases("wikipedia")] - [Description("Search Wikipedia for a given query")] + [Description("Find articles on Wikipedia.")] public async Task Wikipedia(CommandContext ctx, - [Description("Query to search on Wikipedia")] [RemainingText] + [Description("Articles to find on Wikipedia.")] [RemainingText] string query) { if (string.IsNullOrWhiteSpace(query)) return; + await ctx.TriggerTypingAsync(); var results = WikipediaService.GetWikipediaDataAsync(query); - if (results.Error != null || results.Search.Count == 0) + if (results.Error != null || results.Search?.Count == 0) { await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_WIKIPEDIA, ResponseType.Missing) .ConfigureAwait(false); return; } - var output = new DiscordEmbedBuilder() - .WithFooter("Articles retrieved using WikipediaNET") - .WithColor(new DiscordColor("#E7B53B")); + if (results.Search?.Count <= 1) + { + await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_COMMON, ResponseType.Missing) + .ConfigureAwait(false); + return; + } - foreach (var result in results.Search) + while (results.Search?.Count > 0) { - var desc = Regex.Replace( - result.Snippet.Length <= 300 - ? result.Snippet - : result.Snippet.Substring(0, 150) + "...", "<[^>]*>", "") ?? "Article has not content."; + var output = new DiscordEmbedBuilder() + .WithColor(new DiscordColor("#6B6B6B")) + .WithFooter(results.Search.Count - 5 >= 5 + ? "Type 'next' within 10 seconds for the next five articles." + : "There articles are retrieved using WikipediaNET."); - output.AddField(result.Title, $"[[Link]({result.Url.AbsoluteUri})] {desc}"); - } + foreach (var result in results.Search.Take(5)) + { + var desc = Regex.Replace( + result.Snippet.Length <= 300 + ? string.IsNullOrEmpty(result.Snippet) ? "Article has not content." : result.Snippet + : result.Snippet[..150] + "...", "<[^>]*>", ""); + output.AddField(result.Title, $"[[Link]({result.Url.AbsoluteUri})] {desc}"); - await ctx.RespondAsync("Search results for " + Formatter.Bold(query) + " on Wikipedia", output) - .ConfigureAwait(false); + results.Search.Remove(result); + } + + var message = await ctx + .RespondAsync("Search results for " + Formatter.Bold(query) + " on Wikipedia", output) + .ConfigureAwait(false); + + if (results.Search.Count < 5) break; + var interactivity = await BotServices.GetUserInteractivity(ctx, "next", 10).ConfigureAwait(false); + if (interactivity.Result is null) break; + await BotServices.RemoveMessage(interactivity.Result).ConfigureAwait(false); + await BotServices.RemoveMessage(message).ConfigureAwait(false); + } } #endregion COMMAND_WIKIPEDIA diff --git a/src/FlawBOT/Modules/Search/WorldModule.cs b/src/FlawBOT/Modules/Search/WorldModule.cs deleted file mode 100644 index f0415ded..00000000 --- a/src/FlawBOT/Modules/Search/WorldModule.cs +++ /dev/null @@ -1,82 +0,0 @@ -using System; -using System.Linq; -using System.Net; -using System.Threading.Tasks; -using DSharpPlus.CommandsNext; -using DSharpPlus.CommandsNext.Attributes; -using DSharpPlus.Entities; -using FlawBOT.Common; -using FlawBOT.Properties; -using FlawBOT.Services; - -namespace FlawBOT.Modules -{ - [Cooldown(3, 5, CooldownBucketType.Channel)] - public class WorldModule : BaseCommandModule - { - #region COMMAND_IP - - [Command("ip")] - [Aliases("ipstack", "track")] - [Description("Retrieve IP address geolocation information")] - public async Task IpTrack(CommandContext ctx, - [Description("IP Address")] string address) - { - if (string.IsNullOrWhiteSpace(address) || !IPAddress.TryParse(address, out var ip)) - { - await BotServices.SendResponseAsync(ctx, Resources.ERR_INVALID_IP, ResponseType.Missing) - .ConfigureAwait(false); - return; - } - - var results = WorldService.GetIpLocationAsync(ip).Result; - if (results.Type == null) - { - await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_LOCATION, ResponseType.Warning) - .ConfigureAwait(false); - return; - } - - var output = new DiscordEmbedBuilder() - .WithTitle($"{results.City}, {results.Region}, {results.Country}") - .WithDescription($"Coordinates: {results.Latitude}°N, {results.Longitude}°W") - .WithUrl(string.Format(Resources.URL_Google_Maps, results.Latitude, results.Longitude)) - .WithColor(new DiscordColor("#4d2f63")); - await ctx.RespondAsync(output.Build()).ConfigureAwait(false); - } - - #endregion COMMAND_IP - - #region COMMAND_WEATHER - - [Command("weather")] - [Aliases("time", "clock")] - [Description("Retrieve the time and weather for specified location")] - public async Task Weather(CommandContext ctx, - [Description("Location from which to retrieve data")] [RemainingText] - string query) - { - if (string.IsNullOrWhiteSpace(query)) return; - var results = await WorldService.GetWeatherDataAsync(query).ConfigureAwait(false); - if (results is null) - { - await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_LOCATION, ResponseType.Missing) - .ConfigureAwait(false); - return; - } - - Func format = WorldService.CelsiusToFahrenheit; - var output = new DiscordEmbedBuilder() - .WithDescription("Weather in " + results.Location.Name + ", " + results.Location.Country) - .AddField(":partly_sunny: Currently", results.Current.Descriptions.FirstOrDefault(), true) - .AddField(":thermometer: Temperature", - $"{results.Current.Temperature:F1}°C / {format(results.Current.Temperature):F1}°F", true) - .AddField(":droplet: Humidity", $"{results.Current.Humidity}%", true) - .AddField(":clock1: Local Time", results.Location.LocalTime, true) - .WithColor(SharedData.DefaultColor); - await ctx.RespondAsync(output.Build()).ConfigureAwait(false); - } - } - - #endregion COMMAND_WEATHER -} \ No newline at end of file diff --git a/src/FlawBOT/Modules/Search/YoutubeModule.cs b/src/FlawBOT/Modules/Search/YoutubeModule.cs index f1c62675..8d304613 100644 --- a/src/FlawBOT/Modules/Search/YoutubeModule.cs +++ b/src/FlawBOT/Modules/Search/YoutubeModule.cs @@ -16,12 +16,13 @@ public class YouTubeModule : BaseCommandModule [Command("channel")] [Aliases("channels", "chn")] - [Description("Retrieve a list of YouTube channel given a query")] + [Description("Retrieve a list of YouTube channels.")] public async Task YtChannel(CommandContext ctx, - [Description("Channels to find on YouTube")] [RemainingText] + [Description("Channels to find on YouTube.")] [RemainingText] string query) { if (string.IsNullOrWhiteSpace(query)) return; + await ctx.TriggerTypingAsync(); var results = await new YoutubeService().GetEmbeddedResults(query, 5, "channel").ConfigureAwait(false); await ctx.RespondAsync("Search results for " + Formatter.Bold(query) + " on YouTube", results) .ConfigureAwait(false); @@ -33,12 +34,13 @@ public async Task YtChannel(CommandContext ctx, [Command("playlist")] [Aliases("playlists", "list")] - [Description("Retrieve a list of YouTube playlists given a query")] + [Description("Retrieve a list of YouTube playlists.")] public async Task YtPlaylist(CommandContext ctx, - [Description("Playlist to find on YouTube")] [RemainingText] + [Description("Playlists to find on YouTube.")] [RemainingText] string query) { if (string.IsNullOrWhiteSpace(query)) return; + await ctx.TriggerTypingAsync(); var results = await new YoutubeService().GetEmbeddedResults(query, 5, "playlist").ConfigureAwait(false); await ctx.RespondAsync("Search results for " + Formatter.Bold(query) + " on YouTube", results) .ConfigureAwait(false); @@ -50,12 +52,13 @@ public async Task YtPlaylist(CommandContext ctx, [Command("search")] [Aliases("find", "watch")] - [Description("Retrieve the first YouTube search result given a query")] + [Description("Retrieve the first YouTube search result.")] public async Task YtVideo(CommandContext ctx, - [Description("First result video to find on YouTube")] [RemainingText] + [Description("First result video to find on YouTube.")] [RemainingText] string query) { if (string.IsNullOrWhiteSpace(query)) return; + await ctx.TriggerTypingAsync(); var results = await new YoutubeService().GetFirstVideoResultAsync(query).ConfigureAwait(false); await ctx.RespondAsync(results).ConfigureAwait(false); } @@ -66,12 +69,13 @@ public async Task YtVideo(CommandContext ctx, [Command("video")] [Aliases("videos", "vid")] - [Description("Retrieve a list of YouTube videos given a query")] + [Description("Retrieve a list of YouTube videos.")] public async Task YtSearch(CommandContext ctx, - [Description("Video to find on YouTube")] [RemainingText] + [Description("Videos to find on YouTube.")] [RemainingText] string query) { if (string.IsNullOrWhiteSpace(query)) return; + await ctx.TriggerTypingAsync(); var results = await new YoutubeService().GetEmbeddedResults(query, 5, "video").ConfigureAwait(false); await ctx.RespondAsync("Search results for " + Formatter.Bold(query) + " on YouTube", results) .ConfigureAwait(false); diff --git a/src/FlawBOT/Modules/Server/ChannelModule.cs b/src/FlawBOT/Modules/Server/ChannelModule.cs index 9610cf65..d3171a48 100644 --- a/src/FlawBOT/Modules/Server/ChannelModule.cs +++ b/src/FlawBOT/Modules/Server/ChannelModule.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; @@ -7,6 +8,8 @@ using DSharpPlus.CommandsNext; using DSharpPlus.CommandsNext.Attributes; using DSharpPlus.Entities; +using DSharpPlus.Interactivity.Enums; +using DSharpPlus.Interactivity.Extensions; using FlawBOT.Common; using FlawBOT.Properties; using FlawBOT.Services; @@ -15,7 +18,7 @@ namespace FlawBOT.Modules { [Group("channel")] [Aliases("chn", "ch", "c")] - [Description("Commands for controlling channels")] + [Description("Commands for controlling channels.")] [Cooldown(3, 5, CooldownBucketType.Channel)] public class ChannelModule : BaseCommandModule { @@ -23,10 +26,10 @@ public class ChannelModule : BaseCommandModule [Command("category")] [Aliases("createcategory", "newcategory", "ct")] - [Description("Create a new channel category")] + [Description("Create a new channel category.")] [RequirePermissions(Permissions.ManageChannels)] public async Task CreateCategory(CommandContext ctx, - [Description("New category name")] [RemainingText] + [Description("New category name.")] [RemainingText] string name) { if (!BotServices.CheckChannelName(name)) @@ -47,10 +50,10 @@ await ctx.RespondAsync("Successfully created category " + Formatter.Bold(categor [Command("clean")] [Aliases("clear")] - [Description("Remove channel messages")] + [Description("Remove channel messages.")] [RequirePermissions(Permissions.ManageMessages)] public async Task CleanChannel(CommandContext ctx, - [Description("Number of message to remove from the current channel")] + [Description("Number of messages to remove from the current channel.")] int limit = 2) { var messages = await ctx.Channel.GetMessagesAsync(BotServices.LimitToRange(limit)).ConfigureAwait(false); @@ -65,10 +68,10 @@ await ctx.RespondAsync(Formatter.Bold(messages.Count.ToString()) + " message(s) [Command("delete")] [Aliases("remove")] - [Description("Delete a channel. If a channel isn't specified, the current one will be deleted")] + [Description("Delete a channel. If a channel isn't specified, the current one will be deleted.")] [RequirePermissions(Permissions.ManageChannels)] public async Task DeleteChannel(CommandContext ctx, - [Description("Channel to delete")] [RemainingText] + [Description("Channel to delete.")] [RemainingText] DiscordChannel channel = null) { // Set the current channel for deletion if one isn't provided by the user @@ -97,9 +100,9 @@ public async Task DeleteChannel(CommandContext ctx, [Command("info")] [Aliases("i")] - [Description("Print channel information. If a channel isn't specified, the current one will be used")] + [Description("Print channel information. If a channel isn't specified, the current one will be used.")] public Task GetChannel(CommandContext ctx, - [Description("Channel to retrieve information from")] [RemainingText] + [Description("Channel to retrieve information from.")] [RemainingText] DiscordChannel channel = null) { // Set the current channel for viewing if one isn't provided by the user @@ -119,7 +122,7 @@ public Task GetChannel(CommandContext ctx, .AddField("NSFW", channel.IsNSFW ? "Yes" : "No", true) .WithThumbnail(ctx.Guild.IconUrl) .WithFooter("Created on " + channel.CreationTimestamp.DateTime.ToString(CultureInfo.InvariantCulture)) - .WithColor(SharedData.DefaultColor); + .WithColor(Program.Settings.DefaultColor); // Add additional fields depending on the channel type switch (channel.Type) @@ -146,12 +149,12 @@ public Task GetChannel(CommandContext ctx, #region CHANNEL_PURGE [Command("purge")] - [Description("Remove server user's channel messages")] + [Description("Remove server user's channel messages.")] [RequirePermissions(Permissions.ManageMessages)] public async Task Purge(CommandContext ctx, - [Description("Server user whose messages will be purged")] + [Description("Server user whose messages will be purged.")] DiscordMember member, - [Description("Number of messages to purge")] [RemainingText] + [Description("Number of messages to purge.")] [RemainingText] int limit = 0) { var messages = await ctx.Channel.GetMessagesAsync(BotServices.LimitToRange(limit)).ConfigureAwait(false); @@ -167,11 +170,11 @@ await ctx.RespondAsync( [Command("rename")] [Aliases("setname")] - [Description("Rename a channel. If a channel isn't specified, the current one will be used")] + [Description("Rename a channel. If a channel isn't specified, the current one will be used.")] [RequirePermissions(Permissions.ManageChannels)] public async Task SetChannelName(CommandContext ctx, - [Description("Channel to rename")] DiscordChannel channel, - [Description("New channel name")] [RemainingText] + [Description("Channel to rename.")] DiscordChannel channel, + [Description("New channel name.")] [RemainingText] string name) { if (!BotServices.CheckChannelName(name)) @@ -192,11 +195,11 @@ await ctx.RespondAsync("Successfully renamed the channel " + Formatter.Bold(oldN #region COMMAND_TEXT [Command("text")] - [Aliases("createtext", "newtext", "ctc")] - [Description("Create a new text channel")] + [Aliases("createtext", "newtext")] + [Description("Create a new text channel.")] [RequirePermissions(Permissions.ManageChannels)] public async Task CreateText(CommandContext ctx, - [Description("New text channel name")] [RemainingText] + [Description("New text channel name.")] [RemainingText] string name = "") { if (!BotServices.CheckChannelName(name)) @@ -224,11 +227,11 @@ await ctx.RespondAsync("Successfully created the text channel " + Formatter.Bold #region COMMAND_TOPIC [Command("topic")] - [Aliases("settopic", "st")] - [Description("Set current channel's topic")] + [Aliases("settopic")] + [Description("Set current channel's topic.")] [RequirePermissions(Permissions.ManageChannels)] public async Task SetChannelTopic(CommandContext ctx, - [Description("New channel topic")] [RemainingText] + [Description("New channel topic.")] [RemainingText] string topic = "") { if (topic.Length > 1024) @@ -249,11 +252,11 @@ await ctx.RespondAsync("Successfully changed the channel topic to " + Formatter. #region COMMAND_VOICE [Command("voice")] - [Aliases("createvoice", "newvoice", "cvc")] - [Description("Create a new voice channel")] + [Aliases("createvoice", "newvoice")] + [Description("Create a new voice channel.")] [RequirePermissions(Permissions.ManageChannels)] public async Task CreateVoice(CommandContext ctx, - [Description("New voice channel name")] [RemainingText] + [Description("New voice channel name.")] [RemainingText] string name = "") { if (!BotServices.CheckChannelName(name)) @@ -277,5 +280,50 @@ await ctx.RespondAsync("Successfully created the voice channel " + Formatter.Bol } #endregion COMMAND_VOICE + + #region COMMAND_VOTE + + [Command("vote")] + [Aliases("poll")] + [Description("Run a Yay or Nay poll in the current channel.")] + public async Task Poll(CommandContext ctx, + [Description("Question to be asked in the poll.")] [RemainingText] + string question) + { + if (string.IsNullOrWhiteSpace(question)) + { + await BotServices.SendResponseAsync(ctx, Resources.ERR_POLL_QUESTION, ResponseType.Warning) + .ConfigureAwait(false); + return; + } + + // Build the poll question, duration and options. + await ctx.TriggerTypingAsync(); + question = ctx.User.Mention + " asked: " + question; + var interactivity = ctx.Client.GetInteractivity(); + var pollOptions = new List + { + DiscordEmoji.FromName(ctx.Client, ":thumbsup:"), + DiscordEmoji.FromName(ctx.Client, ":thumbsdown:") + }; + var duration = new TimeSpan(0, 3, 10); + var message = await ctx + .RespondAsync(new DiscordEmbedBuilder() + .WithDescription(question + $"\nThis poll ends in {duration.Minutes} minutes.").Build()) + .ConfigureAwait(false); + var results = await interactivity.DoPollAsync(message, pollOptions, PollBehaviour.DeleteEmojis, duration) + .ConfigureAwait(false); + + // Removed the initial poll and return the calculated results + await BotServices.RemoveMessage(message).ConfigureAwait(false); + var output = new DiscordEmbedBuilder() + .WithDescription(question) + .WithFooter("The voting has ended."); + foreach (var vote in results) + output.AddField(vote.Emoji.Name, vote.Voted.Count.ToString(), true); + await ctx.RespondAsync(output.Build()).ConfigureAwait(false); + } + + #endregion COMMAND_VOTE } } \ No newline at end of file diff --git a/src/FlawBOT/Modules/Server/EmojiModule.cs b/src/FlawBOT/Modules/Server/EmojiModule.cs index 05fda30a..a392e428 100644 --- a/src/FlawBOT/Modules/Server/EmojiModule.cs +++ b/src/FlawBOT/Modules/Server/EmojiModule.cs @@ -15,16 +15,16 @@ namespace FlawBOT.Modules { [Group("emoji")] - [Aliases("emojis", "em", "e")] - [Description("Commands for managing server emojis")] + [Aliases("emote")] + [Description("Commands for managing server emojis.")] [Cooldown(3, 5, CooldownBucketType.Channel)] public class EmojiModule : BaseCommandModule { #region COMMAND_ADD [Command("add")] - [Aliases("addnew", "create")] - [Description("Add a new server emoji through URL or as an attachment.")] + [Aliases("new", "create")] + [Description("Add a new server emoji using a URL image.")] [RequirePermissions(Permissions.ManageEmojis)] public async Task CreateEmoji(CommandContext ctx, [Description("Image URL.")] Uri url, @@ -80,8 +80,8 @@ await BotServices.SendResponseAsync(ctx, Resources.ERR_EMOJI_ADD, ResponseType.E #region COMMAND_DELETE [Command("delete")] - [Aliases("remove", "rm", "del")] - [Description("Remove an existing server emoji. Note: Bots can only delete emojis they created.")] + [Aliases("remove")] + [Description("Remove a server emoji. Note: Bots can only delete emojis they created.")] [RequirePermissions(Permissions.ManageEmojis)] public async Task DeleteEmoji(CommandContext ctx, [Description("Server emoji to delete.")] @@ -104,13 +104,13 @@ await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_EMOJI, ResponseType #region COMMAND_EDIT - [Command("modify")] - [Aliases("e", "edit", "rename")] - [Description("Edit the name of an existing server emoji.")] + [Command("rename")] + [Aliases("edit", "modify")] + [Description("Rename a server emoji.")] [RequirePermissions(Permissions.ManageEmojis)] public async Task EditEmoji(CommandContext ctx, [Description("Emoji to rename.")] DiscordEmoji query, - [Description("New name.")] string name) + [Description("New emoji name.")] string name) { try { @@ -138,7 +138,6 @@ await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_EMOJI, ResponseType #region COMMAND_INFO [Command("info")] - [Aliases("i")] [Description("Retrieve server emoji information.")] public async Task GetEmojiInfo(CommandContext ctx, [Description("Server emoji.")] DiscordEmoji query) @@ -158,8 +157,8 @@ public async Task GetEmojiInfo(CommandContext ctx, #region COMMAND_LIST [Command("list")] - [Aliases("print", "l", "ls", "all")] - [Description("Retrieve the list of server emojis.")] + [Aliases("print", "all")] + [Description("Retrieve a list of server emojis.")] public async Task GetEmojiList(CommandContext ctx) { var emojiList = new StringBuilder(); diff --git a/src/FlawBOT/Modules/Server/RoleModule.cs b/src/FlawBOT/Modules/Server/RoleModule.cs index 34e3f6cc..c0869261 100644 --- a/src/FlawBOT/Modules/Server/RoleModule.cs +++ b/src/FlawBOT/Modules/Server/RoleModule.cs @@ -15,21 +15,21 @@ namespace FlawBOT.Modules { [Group("role")] - [Aliases("roles", "rl")] - [Description("Commands for controlling server roles")] + [Aliases("roles")] + [Description("Commands for controlling server roles.")] [Cooldown(3, 5, CooldownBucketType.Guild)] public class RoleModule : BaseCommandModule { #region COMMAND_COLOR [Command("color")] - [Aliases("clr", "setcolor")] - [Description("Set the role color")] + [Aliases("setcolor", "clr")] + [Description("Change the server role color.")] [RequirePermissions(Permissions.ManageRoles)] public async Task ColorRole(CommandContext ctx, - [Description("HEX color code to set for the role")] + [Description("Server role's new HEX color code.")] DiscordColor color, - [Description("Server role to recolor")] [RemainingText] + [Description("Server role to recolor.")] [RemainingText] DiscordRole role) { var regex = new Regex("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$", RegexOptions.Compiled).Match(color.ToString()); @@ -55,10 +55,10 @@ await BotServices.SendResponseAsync(ctx, [Command("create")] [Aliases("new")] - [Description("Create a server role")] + [Description("Create a new server role.")] [RequirePermissions(Permissions.ManageRoles)] public async Task CreateRole(CommandContext ctx, - [Description("New role name")] [RemainingText] + [Description("New role name.")] [RemainingText] string role = "") { if (string.IsNullOrWhiteSpace(role)) @@ -79,10 +79,10 @@ await ctx.RespondAsync("Successfully created the server role " + Formatter.Bold( [Command("delete")] [Aliases("remove")] - [Description("Delete a server role")] + [Description("Delete a server role.")] [RequirePermissions(Permissions.ManageRoles)] public async Task DeleteRole(CommandContext ctx, - [Description("Server role to delete")] [RemainingText] + [Description("Server role to remove.")] [RemainingText] DiscordRole role = null) { if (role is null) @@ -102,10 +102,9 @@ await ctx.RespondAsync("Successfully removed the server role " + Formatter.Bold( #region COMMAND_INFO [Command("info")] - [Aliases("i")] - [Description("Retrieve role information")] + [Description("Retrieve server role information.")] public async Task GetRole(CommandContext ctx, - [Description("Server role information to retrieve")] [RemainingText] + [Description("Server role name.")] [RemainingText] DiscordRole role = null) { if (role is null) @@ -134,9 +133,9 @@ await BotServices.SendResponseAsync(ctx, Resources.ERR_ROLE_EXISTING, ResponseTy #region COMMAND_INROLE [Command("inrole")] - [Description("Retrieve a list of users in a given role")] + [Description("Retrieve a list of users with a given role.")] public async Task UsersInRole(CommandContext ctx, - [Description("Server role")] [RemainingText] + [Description("Server role name.")] [RemainingText] DiscordRole role = null) { if (role is null) @@ -173,10 +172,10 @@ await BotServices #region COMMAND_MENTION [Command("mention")] - [Description("Toggle whether this role can be mentioned by others")] + [Description("Toggle whether this role can be mentioned by others.")] [RequirePermissions(Permissions.ManageRoles)] public async Task MentionRole(CommandContext ctx, - [Description("Server role to toggle")] [RemainingText] + [Description("Server role name.")] [RemainingText] DiscordRole role) { if (role is null) return; @@ -199,12 +198,12 @@ await BotServices.SendResponseAsync(ctx, Formatter.Bold(role.Name) + " is now ** #region COMMAND_REVOKE [Command("revoke")] - [Description("Remove a role from server user")] + [Description("Remove a role from server user.")] [RequirePermissions(Permissions.ManageRoles)] public async Task RevokeRole(CommandContext ctx, - [Description("Server user to get revoked")] + [Description("Server user to get revoked.")] DiscordMember member, - [Description("Server role to revoke from user")] [RemainingText] + [Description("Server role name.")] [RemainingText] DiscordRole role) { if (role != null) @@ -221,10 +220,10 @@ await ctx.RespondAsync(Formatter.Bold(member.DisplayName) + " has been removed f #region COMMAND_REVOKE_ALL [Command("revokeall")] - [Description("Remove all role from server user")] + [Description("Remove all role from a server user.")] [RequirePermissions(Permissions.ManageRoles)] public async Task RevokeAllRoles(CommandContext ctx, - [Description("Server user to get revoked")] + [Description("Server user name.")] DiscordMember member) { if (!member.Roles.Any()) @@ -251,13 +250,13 @@ await ctx.RespondAsync("Removed all roles from " + Formatter.Bold(member.Display #region COMMAND_ASSIGN [Command("setrole")] - [Aliases("addrole", "sr")] - [Description("Assign a role to server user")] + [Aliases("addrole")] + [Description("Assign a role to server user.")] [RequirePermissions(Permissions.ManageRoles)] public async Task SetUserRole(CommandContext ctx, - [Description("Server user to get role assigned")] + [Description("Server user name.")] DiscordMember member, - [Description("Server role to assign to the user")] [RemainingText] + [Description("Server role name.")] [RemainingText] DiscordRole role) { member ??= ctx.Member; @@ -272,10 +271,10 @@ await ctx.RespondAsync(member.DisplayName + " been granted the role " + Formatte [Command("show")] [Aliases("display", "hide")] - [Description("Toggle whether this role is seen or not")] + [Description("Toggle whether this role is seen or not.")] [RequirePermissions(Permissions.ManageRoles)] public async Task SidebarRole(CommandContext ctx, - [Description("Server role to toggle")] [RemainingText] + [Description("Server role name.")] [RemainingText] DiscordRole role) { if (role is null) return; diff --git a/src/FlawBOT/Modules/Server/ServerModule.cs b/src/FlawBOT/Modules/Server/ServerModule.cs index 717d6e3f..95ae17a4 100644 --- a/src/FlawBOT/Modules/Server/ServerModule.cs +++ b/src/FlawBOT/Modules/Server/ServerModule.cs @@ -14,7 +14,7 @@ namespace FlawBOT.Modules { [Group("server")] [Aliases("guild")] - [Description("Commands for controlling server")] + [Description("Commands for controlling server.")] [Cooldown(3, 5, CooldownBucketType.Guild)] public class ServerModule : BaseCommandModule { @@ -22,10 +22,10 @@ public class ServerModule : BaseCommandModule [Command("avatar")] [Aliases("setavatar")] - [Description("Set server avatar")] + [Description("Change the server avatar.")] [RequireUserPermissions(Permissions.ManageGuild)] public async Task SetServerAvatar(CommandContext ctx, - [Description("Image URL. Must be in jpg, png or img format.")] + [Description("URL image in JPG, PNG or IMG format.")] string query) { try @@ -47,8 +47,7 @@ await BotServices #region COMMAND_INFO [Command("info")] - [Aliases("i")] - [Description("Retrieve server information")] + [Description("Retrieve server information.")] public async Task GetServer(CommandContext ctx) { var output = new DiscordEmbedBuilder() @@ -86,7 +85,7 @@ public async Task GetServer(CommandContext ctx) #region COMMAND_INVITE [Command("invite")] - [Description("Retrieve an instant invite link to the server")] + [Description("Retrieve an instant invite link to the server.")] public async Task Invite(CommandContext ctx) { await ctx.RespondAsync("Instant Invite to " + Formatter.Bold(ctx.Guild.Name) + ":https://discord.gg/" + @@ -98,10 +97,10 @@ await ctx.RespondAsync("Instant Invite to " + Formatter.Bold(ctx.Guild.Name) + " #region COMMAND_PRUNE [Command("prune")] - [Description("Prune inactive server members")] + [Description("Prune inactive server members.")] [RequirePermissions(Permissions.DeafenMembers)] public async Task Prune(CommandContext ctx, - [Description("Number of days the user had to be inactive to get pruned")] + [Description("Number of days the user had to be inactive to get pruned.")] int days = 7) { if (days < 1 || days > 30) @@ -132,10 +131,10 @@ await BotServices [Command("rename")] [Aliases("setname")] - [Description("Set server name")] + [Description("Change the server name.")] [RequireUserPermissions(Permissions.ManageGuild)] public async Task SetServerName(CommandContext ctx, - [Description("New server name")] [RemainingText] + [Description("New server name.")] [RemainingText] string name = "") { if (string.IsNullOrWhiteSpace(name) || name.Length > 100) @@ -156,10 +155,10 @@ await BotServices [Command("warn")] [Aliases("scold")] - [Description("Direct message user with a warning")] + [Description("Direct message user with a warning.")] public async Task Warn(CommandContext ctx, - [Description("Server user to warn")] DiscordMember member, - [Description("Warning message")] [RemainingText] + [Description("Server user to warn.")] DiscordMember member, + [Description("Warning message.")] [RemainingText] string reason = null) { var output = new DiscordEmbedBuilder() diff --git a/src/FlawBOT/Modules/Server/UserModule.cs b/src/FlawBOT/Modules/Server/UserModule.cs index 2fc90c4d..d3b3a217 100644 --- a/src/FlawBOT/Modules/Server/UserModule.cs +++ b/src/FlawBOT/Modules/Server/UserModule.cs @@ -12,8 +12,8 @@ namespace FlawBOT.Modules { [Group("user")] - [Aliases("users", "u", "usr")] - [Description("Commands for controlling server users")] + [Aliases("users", "usr")] + [Description("Commands for controlling server users.")] [Cooldown(3, 5, CooldownBucketType.Channel)] public class UserModule : BaseCommandModule { @@ -21,9 +21,9 @@ public class UserModule : BaseCommandModule [Command("avatar")] [Aliases("getavatar", "image", "pfp")] - [Description("Retrieve server user's profile picture")] + [Description("Retrieve server user's profile picture.")] public async Task GetAvatar(CommandContext ctx, - [Description("Server user whose profile picture to retrieve")] [RemainingText] + [Description("Server user whose profile picture to retrieve.")] [RemainingText] DiscordMember member) { member ??= ctx.Member; @@ -38,11 +38,11 @@ public async Task GetAvatar(CommandContext ctx, #region COMMAND_BAN [Command("ban")] - [Description("Ban server user")] + [Description("Ban a server user.")] [RequirePermissions(Permissions.BanMembers)] public async Task Ban(CommandContext ctx, - [Description("Server user to ban")] DiscordMember member, - [Description("Reason for the ban")] [RemainingText] + [Description("Server user to ban.")] DiscordMember member, + [Description("Reason for the ban.")] [RemainingText] string reason = null) { if (ctx.Member.Id == member.Id) @@ -63,11 +63,11 @@ await BotServices.SendUserStateChangeAsync(ctx, UserStateChange.Ban, member, [Command("deafen")] [Aliases("deaf")] - [Description("Deafen server user")] + [Description("Deafen a server user.")] [RequirePermissions(Permissions.DeafenMembers)] public async Task DeafenUser(CommandContext ctx, - [Description("Server user to deafen")] DiscordMember member, - [Description("Reason for the deafen")] [RemainingText] + [Description("Server user to deafen.")] DiscordMember member, + [Description("Reason for the deafen.")] [RemainingText] string reason = null) { if (member.IsDeafened) @@ -88,10 +88,9 @@ await BotServices.SendUserStateChangeAsync(ctx, UserStateChange.Deafen, member, #region COMMAND_INFO [Command("info")] - [Aliases("i")] - [Description("Retrieve user information")] + [Description("Retrieve server user's information.")] public async Task GetUser(CommandContext ctx, - [Description("Server user whose information to retrieve")] [RemainingText] + [Description("Server user whose information to retrieve.")] [RemainingText] DiscordMember member) { member ??= ctx.Member; @@ -131,11 +130,11 @@ public async Task GetUser(CommandContext ctx, [Command("kick")] [Aliases("remove")] - [Description("Kick server user")] + [Description("Kick a user from the server.")] [RequirePermissions(Permissions.KickMembers)] public async Task Kick(CommandContext ctx, - [Description("Server user to kick")] DiscordMember member, - [Description("Reason for the kick")] [RemainingText] + [Description("Server user to kick.")] DiscordMember member, + [Description("Reason for the kick.")] [RemainingText] string reason = null) { if (ctx.Member.Id == member.Id) @@ -156,11 +155,11 @@ await BotServices.SendUserStateChangeAsync(ctx, UserStateChange.Kick, member, [Command("mute")] [Aliases("silence")] - [Description("Mute server user")] + [Description("Mute a server user.")] [RequirePermissions(Permissions.MuteMembers)] public async Task Mute(CommandContext ctx, - [Description("Server user to mute")] DiscordMember member, - [Description("Reason for the mute")] [RemainingText] + [Description("Server user to mute.")] DiscordMember member, + [Description("Reason for the mute.")] [RemainingText] string reason = null) { if (member.IsMuted) @@ -182,12 +181,12 @@ await BotServices.SendUserStateChangeAsync(ctx, UserStateChange.Mute, member, [Command("nickname")] [Aliases("setnick", "nick")] - [Description("Set server user's nickname")] + [Description("Change server user's nickname.")] [RequireUserPermissions(Permissions.ChangeNickname)] public async Task SetUserName(CommandContext ctx, - [Description("Server user to nickname")] + [Description("Server user name.")] DiscordMember member, - [Description("The new nickname")] [RemainingText] + [Description("New nickname for the name.")] [RemainingText] string name = null) { member ??= ctx.Member; @@ -204,12 +203,11 @@ public async Task SetUserName(CommandContext ctx, #region COMMAND_PERMS [Command("perms")] - [Aliases("prm")] - [Description("Retrieve server user's permissions")] + [Description("Retrieve server user's permissions.")] public async Task GetPermissionsList(CommandContext ctx, - [Description("Server user whose permissions to retrieve")] + [Description("Server user name.")] DiscordMember member = null, - [Description("Server channel")] DiscordChannel channel = null) + [Description("Server channel.")] DiscordChannel channel = null) { member ??= ctx.Member; channel ??= ctx.Channel; @@ -228,12 +226,12 @@ public async Task GetPermissionsList(CommandContext ctx, #region COMMAND_UNBAN [Command("unban")] - [Description("Unban server user")] + [Description("Unban a server user.")] [RequirePermissions(Permissions.BanMembers)] public async Task Unban(CommandContext ctx, - [Description("Discord user ID to unban from the server")] + [Description("Discord user ID to unban from the server.")] ulong userId, - [Description("Reason for the deafen")] [RemainingText] + [Description("Reason for the unban.")] [RemainingText] string reason = null) { var member = await ctx.Client.GetUserAsync(userId).ConfigureAwait(false); @@ -248,12 +246,12 @@ public async Task Unban(CommandContext ctx, [Command("undeafen")] [Aliases("undeaf")] - [Description("Undeafen server user")] + [Description("Undeafen a server user.")] [RequirePermissions(Permissions.DeafenMembers)] public async Task Undeafen(CommandContext ctx, - [Description("Server user to undeafen")] + [Description("Server user to undeafen.")] DiscordMember member, - [Description("Reason for the deafen")] [RemainingText] + [Description("Reason for the deafen.")] [RemainingText] string reason = null) { await member.SetDeafAsync(false, reason).ConfigureAwait(false); @@ -267,11 +265,11 @@ await BotServices.SendUserStateChangeAsync(ctx, UserStateChange.Undeafen, member #region COMMAND_UNMUTE [Command("unmute")] - [Description("Unmute server user")] + [Description("Unmute a server user.")] [RequirePermissions(Permissions.MuteMembers)] public async Task Unmute(CommandContext ctx, - [Description("Server user to unmute")] DiscordMember member, - [Description("Reason for the deafen")] [RemainingText] + [Description("Server user to unmute.")] DiscordMember member, + [Description("Reason for the deafen.")] [RemainingText] string reason = null) { await member.SetMuteAsync(false, reason).ConfigureAwait(false); diff --git a/src/FlawBOT/Program.cs b/src/FlawBOT/Program.cs index 85fd42dd..b8e35217 100644 --- a/src/FlawBOT/Program.cs +++ b/src/FlawBOT/Program.cs @@ -1,10 +1,12 @@ using System; using System.Collections.Generic; +using System.IO; +using System.Text; using System.Threading; using System.Threading.Tasks; using FlawBOT.Common; using FlawBOT.Properties; -using FlawBOT.Services; +using Newtonsoft.Json; namespace FlawBOT { @@ -12,6 +14,7 @@ internal sealed class Program { private static List Shards { get; } = new(); private static CancellationTokenSource CancelTokenSource { get; } = new(); + public static BotSettings Settings { get; set; } public static void Main(string[] args) { @@ -25,13 +28,14 @@ private static async Task RunBotAsync(string[] args) // Set a command for canceling the bot process Console.CancelKeyPress += ConsoleOnCancelKeyPress; - // Load the bot configuration - var service = new BotServices(); - if (!service.LoadConfiguration()) return; + // Load Settings + if (!File.Exists("config.json")) return; + var json = new StreamReader(File.OpenRead("config.json"), new UTF8Encoding(false)).ReadToEnd(); + Settings = JsonConvert.DeserializeObject(json); // Generate a list of shards var botList = new List(); - for (var i = 0; i < SharedData.ShardCount; i++) + for (var i = 0; i < Settings.ShardCount; i++) { var client = new FlawBot(i); Shards.Add(client); @@ -46,7 +50,7 @@ private static async Task RunBotAsync(string[] args) catch (Exception ex) { Console.WriteLine(Resources.ERR_EXCEPTION, ex.Message); - if (!(ex.InnerException is null)) + if (ex.InnerException is not null) Console.WriteLine(Resources.ERR_EXCEPTION_INNER, ex.InnerException.Message); Console.ReadKey(); } diff --git a/src/FlawBOT/Properties/Resources.Designer.cs b/src/FlawBOT/Properties/Resources.Designer.cs index bde3d040..d970f785 100644 --- a/src/FlawBOT/Properties/Resources.Designer.cs +++ b/src/FlawBOT/Properties/Resources.Designer.cs @@ -366,6 +366,15 @@ internal static string URL_Amiibo { } } + /// + /// Looks up a localized string similar to http://www.flawbot.criticalflaw.ca/. + /// + internal static string URL_BOT_Docs { + get { + return ResourceManager.GetString("URL_BOT_Docs", resourceCulture); + } + } + /// /// Looks up a localized string similar to https://github.com/CriticalFlaw/FlawBOT/. /// diff --git a/src/FlawBOT/Properties/Resources.resx b/src/FlawBOT/Properties/Resources.resx index ae472f95..3d7787c2 100644 --- a/src/FlawBOT/Properties/Resources.resx +++ b/src/FlawBOT/Properties/Resources.resx @@ -317,4 +317,7 @@ The following information will be sent to the developer for investigation: User ID, Server ID, Server Name and Server Owner Name. + + http://www.flawbot.criticalflaw.ca/ + \ No newline at end of file diff --git a/src/FlawBOT/Services/Bot/BotService.cs b/src/FlawBOT/Services/Bot/BotService.cs index 5a6fe3d7..9df9674b 100644 --- a/src/FlawBOT/Services/Bot/BotService.cs +++ b/src/FlawBOT/Services/Bot/BotService.cs @@ -1,16 +1,13 @@ using System; using System.IO; using System.Net; -using System.Text; using System.Threading.Tasks; using DSharpPlus.CommandsNext; using DSharpPlus.Entities; using DSharpPlus.Interactivity; using DSharpPlus.Interactivity.Extensions; using FlawBOT.Common; -using FlawBOT.Models; using FlawBOT.Properties; -using Newtonsoft.Json; namespace FlawBOT.Services { @@ -85,13 +82,5 @@ await SendResponseAsync(ctx, Resources.URL_INVALID_IMG, ResponseType.Warning) return stream; } - - public bool LoadConfiguration() - { - if (!File.Exists("config.json")) return false; - var json = new StreamReader(File.OpenRead("config.json"), new UTF8Encoding(false)).ReadToEnd(); - SharedData.Tokens = JsonConvert.DeserializeObject(json); - return true; - } } } \ No newline at end of file diff --git a/src/FlawBOT/Services/Bot/LavalinkService.cs b/src/FlawBOT/Services/Bot/LavalinkService.cs index 095cdbfe..0707a76c 100644 --- a/src/FlawBOT/Services/Bot/LavalinkService.cs +++ b/src/FlawBOT/Services/Bot/LavalinkService.cs @@ -6,7 +6,6 @@ using DSharpPlus.Lavalink.EventArgs; using DSharpPlus.Net; using Emzi0767.Utilities; -using FlawBOT.Common; using Microsoft.Extensions.Logging; namespace FlawBOT.Services @@ -21,13 +20,13 @@ public LavalinkService(DiscordClient client) Discord.Ready += Client_Ready; _trackException = new AsyncEvent( - $"{SharedData.Name.ToUpperInvariant()}_LAVALINK_TRACK_EXCEPTION", + $"{Program.Settings.Name.ToUpperInvariant()}_LAVALINK_TRACK_EXCEPTION", TimeSpan.Zero, EventExceptionHandler); } private DiscordClient Discord { get; } - public static EventId LogEvent { get; } = new(1001, SharedData.Name); + public static EventId LogEvent { get; } = new(1001, Program.Settings.Name); public LavalinkNodeConnection Node { get; private set; } @@ -37,14 +36,17 @@ private Task Client_Ready(DiscordClient sender, ReadyEventArgs e) _ = Task.Run(async () => { var lava = sender.GetLavalink(); - Node = await lava.ConnectAsync(new LavalinkConfiguration + if (lava is not null) { - Password = "youshallnotpass", - SocketEndpoint = new ConnectionEndpoint("127.0.0.1", 2333), - RestEndpoint = new ConnectionEndpoint("127.0.0.1", 2333) - }); + Node = await lava.ConnectAsync(new LavalinkConfiguration + { + Password = "youshallnotpass", + SocketEndpoint = new ConnectionEndpoint("192.168.2.38", 2333), + RestEndpoint = new ConnectionEndpoint("192.168.2.38", 2333) + }); - Node.TrackException += LavalinkNode_TrackException; + Node.TrackException += LavalinkNode_TrackException; + } }); return Task.CompletedTask; diff --git a/src/FlawBOT/Services/Bot/MusicService.cs b/src/FlawBOT/Services/Bot/MusicService.cs index 5e626dd9..6922afb1 100644 --- a/src/FlawBOT/Services/Bot/MusicService.cs +++ b/src/FlawBOT/Services/Bot/MusicService.cs @@ -26,7 +26,7 @@ public async Task GetOrCreateDataAsync(DiscordGuild server) if (MusicData.TryGetValue(server.Id, out var player)) return player; - return MusicData.AddOrUpdate(server.Id, new MusicPlayer(Lavalink), (k, v) => v); + return MusicData.AddOrUpdate(server.Id, new MusicPlayer(Lavalink), (_, v) => v); } public Task GetTracksAsync(Uri uri) diff --git a/src/FlawBOT/Services/Games/PokemonService.cs b/src/FlawBOT/Services/Games/NintendoService.cs similarity index 77% rename from src/FlawBOT/Services/Games/PokemonService.cs rename to src/FlawBOT/Services/Games/NintendoService.cs index 078b02ae..56c3dad0 100644 --- a/src/FlawBOT/Services/Games/PokemonService.cs +++ b/src/FlawBOT/Services/Games/NintendoService.cs @@ -2,14 +2,30 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using FlawBOT.Models; using FlawBOT.Properties; +using Newtonsoft.Json; using PokemonTcgSdk; using PokemonTcgSdk.Models; namespace FlawBOT.Services { - public class PokemonService : HttpHandler + public class NintendoService : HttpHandler { + public static async Task GetAmiiboDataAsync(string query) + { + try + { + var results = await Http.GetStringAsync(string.Format(Resources.URL_Amiibo, query.ToLowerInvariant())) + .ConfigureAwait(false); + return JsonConvert.DeserializeObject(results); + } + catch + { + return null; + } + } + private static List PokemonList { get; set; } = new(); /// diff --git a/src/FlawBOT/Services/Games/SpeedrunService.cs b/src/FlawBOT/Services/Games/SpeedrunService.cs index 5fbacbc8..d4d6a095 100644 --- a/src/FlawBOT/Services/Games/SpeedrunService.cs +++ b/src/FlawBOT/Services/Games/SpeedrunService.cs @@ -57,7 +57,7 @@ public static async Task GetSpeedrunGameIdAsync(string query) var results = await Http .GetStringAsync(string.Format(Resources.URL_Speedrun, Uri.EscapeUriString(query.Trim()))) .ConfigureAwait(false); - return JsonConvert.DeserializeObject(results).Data.First().Id; + return JsonConvert.DeserializeObject(results)?.Data.First().Id; } catch { @@ -82,7 +82,7 @@ public static async Task GetSpeedrunExtraAsync(List queryList, S .GetStringAsync(string.Format(Resources.URL_Speedrun_Extras, search.ToString().ToLowerInvariant(), query)) .ConfigureAwait(false); - var name = JsonConvert.DeserializeObject(output).Data.Name; + var name = JsonConvert.DeserializeObject(output)?.Data.Name; results.Append(name).Append(!query.Equals(queryList.Take(3).Last()) ? ", " : string.Empty); } diff --git a/src/FlawBOT/Services/Games/SteamService.cs b/src/FlawBOT/Services/Games/SteamService.cs index 7f3186aa..ecc9314f 100644 --- a/src/FlawBOT/Services/Games/SteamService.cs +++ b/src/FlawBOT/Services/Games/SteamService.cs @@ -3,7 +3,6 @@ using System.Linq; using System.Net.Http; using System.Threading.Tasks; -using FlawBOT.Common; using FlawBOT.Properties; using Microsoft.Extensions.Options; using Steam.Models; @@ -34,7 +33,7 @@ public static async Task GetSteamAppAsync(string query .First(n => string.Equals(n.Name, query, StringComparison.InvariantCultureIgnoreCase)).AppId; var factoryOptions = new SteamWebInterfaceFactoryOptions { - SteamWebApiKey = SharedData.Tokens.SteamToken + SteamWebApiKey = Program.Settings.Tokens.SteamToken }; return await new SteamWebInterfaceFactory(Options.Create(factoryOptions)).CreateSteamStoreInterface() .GetStoreAppDetailsAsync(appId).ConfigureAwait(false); @@ -45,11 +44,11 @@ public static async Task GetSteamAppAsync(string query } } - public static async Task UpdateSteamAppListAsync() + public static async Task UpdateSteamAppListAsync(string token) { try { - _steamInterface = new SteamWebInterfaceFactory(SharedData.Tokens.SteamToken); + _steamInterface = new SteamWebInterfaceFactory(token); SteamAppList = await _steamInterface.CreateSteamWebInterface(new HttpClient()) .GetAppListAsync(); return true; @@ -68,11 +67,11 @@ public static async Task UpdateSteamAppListAsync() /// /// Call the Steam API for summary data on a given user. /// - public static async Task> GetSteamProfileAsync(string query) + public static async Task> GetSteamProfileAsync(string token, string query) { try { - _steamInterface = new SteamWebInterfaceFactory(SharedData.Tokens.SteamToken); + _steamInterface = new SteamWebInterfaceFactory(token); var steam = _steamInterface.CreateSteamWebInterface(new HttpClient()); var userId = ulong.TryParse(query, out var steamId) ? steamId : 0; if (userId != 0) return await steam.GetPlayerSummaryAsync(userId).ConfigureAwait(false); diff --git a/src/FlawBOT/Services/Games/TeamFortressService.cs b/src/FlawBOT/Services/Games/TeamFortressService.cs index f7b90607..2fa0b421 100644 --- a/src/FlawBOT/Services/Games/TeamFortressService.cs +++ b/src/FlawBOT/Services/Games/TeamFortressService.cs @@ -3,7 +3,6 @@ using System.Linq; using System.Net.Http; using System.Threading.Tasks; -using FlawBOT.Common; using FlawBOT.Properties; using SteamWebAPI2.Interfaces; using SteamWebAPI2.Models.GameEconomy; @@ -19,17 +18,17 @@ public class TeamFortressService : HttpHandler #region NEWS - public static async Task> GetNewsArticlesAsync(int page = 0, string provider = "") + public static async Task> GetNewsArticlesAsync(string token, int page = 0, string provider = "") { List results; if (page > 0) - results = await new TeamworkClient(SharedData.Tokens.TeamworkToken).GetNewsByPageAsync(page) + results = await new TeamworkClient(token).GetNewsByPageAsync(page) .ConfigureAwait(false); else if (provider != string.Empty) - results = await new TeamworkClient(SharedData.Tokens.TeamworkToken).GetNewsByProviderAsync(provider) + results = await new TeamworkClient(token).GetNewsByProviderAsync(provider) .ConfigureAwait(false); else - results = await new TeamworkClient(SharedData.Tokens.TeamworkToken).GetNewsOverviewAsync() + results = await new TeamworkClient(token).GetNewsOverviewAsync() .ConfigureAwait(false); return results.Where(x => x.Type != "tf2-notification").ToList(); } @@ -38,9 +37,10 @@ public static async Task> GetNewsArticlesAsync(int page = 0, string p #region CREATORS - public static async Task> GetContentCreatorAsync(ulong query) + public static async Task> GetContentCreatorAsync(string token, ulong query) { - return await new TeamworkClient(SharedData.Tokens.TeamworkToken).GetYouTubeCreatorAsync(query.ToString()) + return await new TeamworkClient(token) + .GetYouTubeCreatorAsync(query.ToString()) .ConfigureAwait(false); } @@ -53,11 +53,11 @@ public static SchemaItem GetSchemaItem(string query) return ItemSchemaList.Find(n => n.ItemName.Contains(query, StringComparison.InvariantCultureIgnoreCase)); } - public static async Task UpdateTf2SchemaAsync() + public static async Task UpdateTf2SchemaAsync(string token) { try { - _steamInterface = new SteamWebInterfaceFactory(SharedData.Tokens.SteamToken); + _steamInterface = new SteamWebInterfaceFactory(token); var steam = _steamInterface.CreateSteamWebInterface(AppId.TeamFortress2, new HttpClient()); var games = await steam.GetSchemaItemsForTF2Async().ConfigureAwait(false); ItemSchemaList.Clear(); @@ -77,44 +77,44 @@ public static async Task UpdateTf2SchemaAsync() #region SERVERS - public static async Task GetGameModeInfoAsync(string query) + public static async Task GetGameModeInfoAsync(string token, string query) { - return await new TeamworkClient(SharedData.Tokens.TeamworkToken).GetGameModeAsync(query) + return await new TeamworkClient(token).GetGameModeAsync(query) .ConfigureAwait(false); } - public static async Task> GetServersByGameModeAsync(string query) + public static async Task> GetServersByGameModeAsync(string token, string query) { - return await new TeamworkClient(SharedData.Tokens.TeamworkToken).GetServerListByGameModeAsync(query) + return await new TeamworkClient(token).GetServerListByGameModeAsync(query) .ConfigureAwait(false); } - public static async Task> GetCustomServerListsAsync() + public static async Task> GetCustomServerListsAsync(string token) { - return await new TeamworkClient(SharedData.Tokens.TeamworkToken).GetServerListsAsync() + return await new TeamworkClient(token).GetServerListsAsync() .ConfigureAwait(false); } - public static string GetServerInfo(string address) + public static string GetServerInfo(string token, string address) { - return new TeamworkClient(SharedData.Tokens.TeamworkToken).GetServerBanner(address); + return new TeamworkClient(token).GetServerBanner(address); } #endregion SERVERS #region MAPS - public static async Task GetMapStatsAsync(string query) + public static async Task GetMapStatsAsync(string token, string query) { - var map = new TeamworkClient(SharedData.Tokens.TeamworkToken).GetMapsBySearchAsync(query).Result + var map = new TeamworkClient(token).GetMapsBySearchAsync(query).Result .FirstOrDefault()?.Name; - return await new TeamworkClient(SharedData.Tokens.TeamworkToken).GetMapStatsAsync(map) + return await new TeamworkClient(token).GetMapStatsAsync(map) .ConfigureAwait(false); } - public static async Task GetMapThumbnailAsync(string query) + public static async Task GetMapThumbnailAsync(string token, string query) { - return await new TeamworkClient(SharedData.Tokens.TeamworkToken).GetMapThumbnailAsync(query) + return await new TeamworkClient(token).GetMapThumbnailAsync(query) .ConfigureAwait(false); } diff --git a/src/FlawBOT/Services/Search/AmiiboService.cs b/src/FlawBOT/Services/Search/AmiiboService.cs deleted file mode 100644 index d6b0ae5c..00000000 --- a/src/FlawBOT/Services/Search/AmiiboService.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Threading.Tasks; -using FlawBOT.Models; -using FlawBOT.Properties; -using Newtonsoft.Json; - -namespace FlawBOT.Services -{ - public class AmiiboService : HttpHandler - { - public static async Task GetAmiiboDataAsync(string query) - { - try - { - var results = await Http.GetStringAsync(string.Format(Resources.URL_Amiibo, query.ToLowerInvariant())) - .ConfigureAwait(false); - return JsonConvert.DeserializeObject(results); - } - catch - { - return null; - } - } - } -} \ No newline at end of file diff --git a/src/FlawBOT/Services/Search/ImgurService.cs b/src/FlawBOT/Services/Search/ImgurService.cs index 41db88a9..f1085878 100644 --- a/src/FlawBOT/Services/Search/ImgurService.cs +++ b/src/FlawBOT/Services/Search/ImgurService.cs @@ -1,7 +1,6 @@ using System; using System.Linq; using System.Threading.Tasks; -using FlawBOT.Common; using Imgur.API.Authentication.Impl; using Imgur.API.Endpoints.Impl; using Imgur.API.Enums; @@ -11,11 +10,11 @@ namespace FlawBOT.Services { public static class ImgurService { - public static async Task GetImgurGalleryAsync(string query, + public static async Task GetImgurGalleryAsync(string token, string query, GallerySortOrder order = GallerySortOrder.Top, TimeWindow time = TimeWindow.All) { var random = new Random(); - var imgur = new ImgurClient(SharedData.Tokens.ImgurToken); + var imgur = new ImgurClient(token); var endpoint = new GalleryEndpoint(imgur); var gallery = string.IsNullOrWhiteSpace(query) ? (await endpoint.GetRandomGalleryAsync().ConfigureAwait(false)).ToList() diff --git a/src/FlawBOT/Services/Misc/MiscService.cs b/src/FlawBOT/Services/Search/MiscService.cs similarity index 85% rename from src/FlawBOT/Services/Misc/MiscService.cs rename to src/FlawBOT/Services/Search/MiscService.cs index 7bb2af8e..cc9e6303 100644 --- a/src/FlawBOT/Services/Misc/MiscService.cs +++ b/src/FlawBOT/Services/Search/MiscService.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Immutable; +using System.Net; using System.Threading.Tasks; using FlawBOT.Models; using FlawBOT.Properties; @@ -56,5 +57,12 @@ public static async Task GetDogPhotoAsync() var results = await Http.GetStringAsync(Resources.URL_DogPhoto).ConfigureAwait(false); return JsonConvert.DeserializeObject(results); } + + public static async Task GetIpLocationAsync(IPAddress query) + { + var result = await Http.GetStringAsync(string.Format(Resources.URL_IPStack, query)) + .ConfigureAwait(false); + return JsonConvert.DeserializeObject(result); + } } } \ No newline at end of file diff --git a/src/FlawBOT/Services/Search/NASAService.cs b/src/FlawBOT/Services/Search/NASAService.cs index b73b1ea9..ad942d96 100644 --- a/src/FlawBOT/Services/Search/NASAService.cs +++ b/src/FlawBOT/Services/Search/NASAService.cs @@ -1,5 +1,4 @@ using System.Threading.Tasks; -using FlawBOT.Common; using FlawBOT.Models; using FlawBOT.Properties; using Newtonsoft.Json; @@ -8,9 +7,10 @@ namespace FlawBOT.Services { public class NasaService : HttpHandler { - public static async Task GetNasaImageAsync() + public static async Task GetNasaImageAsync(string token) { - var results = await Http.GetStringAsync(string.Format(Resources.URL_NASA, SharedData.Tokens.NasaToken)) + var results = await Http + .GetStringAsync(string.Format(Resources.URL_NASA, token)) .ConfigureAwait(false); return JsonConvert.DeserializeObject(results); } diff --git a/src/FlawBOT/Services/Search/NewsService.cs b/src/FlawBOT/Services/Search/NewsService.cs index 093c3613..98941267 100644 --- a/src/FlawBOT/Services/Search/NewsService.cs +++ b/src/FlawBOT/Services/Search/NewsService.cs @@ -1,5 +1,4 @@ using System.Threading.Tasks; -using FlawBOT.Common; using FlawBOT.Models; using FlawBOT.Properties; using Newtonsoft.Json; @@ -8,10 +7,10 @@ namespace FlawBOT.Services { public class NewsService : HttpHandler { - public static async Task GetNewsDataAsync(string query = "") + public static async Task GetNewsDataAsync(string token, string query = "") { var results = await Http - .GetStringAsync(string.Format(Resources.URL_News, query, SharedData.Tokens.NewsToken)) + .GetStringAsync(string.Format(Resources.URL_News, query, token)) .ConfigureAwait(false); return JsonConvert.DeserializeObject(results); } diff --git a/src/FlawBOT/Services/Search/OMDBService.cs b/src/FlawBOT/Services/Search/OMDBService.cs index dd5b7f4a..e41b5f36 100644 --- a/src/FlawBOT/Services/Search/OMDBService.cs +++ b/src/FlawBOT/Services/Search/OMDBService.cs @@ -1,5 +1,4 @@ using System.Threading.Tasks; -using FlawBOT.Common; using OMDbSharp; using OMDbSharp.Objects; @@ -7,15 +6,15 @@ namespace FlawBOT.Services { public static class OmdbService { - public static async Task GetMovieDataAsync(string query) + public static async Task GetMovieDataAsync(string token, string query) { - return await new OMDbClient(SharedData.Tokens.OmdbToken, false) + return await new OMDbClient(token, false) .GetItemByTitle(query.ToLowerInvariant().Replace("&", "%26")).ConfigureAwait(false); } - public static async Task GetMovieListAsync(string query) + public static async Task GetMovieListAsync(string token, string query) { - return await new OMDbClient(SharedData.Tokens.OmdbToken, false) + return await new OMDbClient(token, false) .GetItemList(query.ToLowerInvariant().Replace("&", "%26")).ConfigureAwait(false); } } diff --git a/src/FlawBOT/Services/Search/SimpsonsService.cs b/src/FlawBOT/Services/Search/SimpsonsService.cs index f6d31119..d7152669 100644 --- a/src/FlawBOT/Services/Search/SimpsonsService.cs +++ b/src/FlawBOT/Services/Search/SimpsonsService.cs @@ -31,12 +31,12 @@ public static async Task GetSimpsonsGifAsync(SiteRoot site) .ConfigureAwait(false); var content = JsonConvert.DeserializeObject(result); var framesResult = await Http - .GetStringAsync(string.Format(Resources.URL_Simpsons_Frames, site, content.Episode.Key, + .GetStringAsync(string.Format(Resources.URL_Simpsons_Frames, site, content?.Episode.Key, content.Frame.Timestamp)) .ConfigureAwait(false); var frames = JsonConvert.DeserializeObject>(framesResult); - var start = frames.FirstOrDefault()?.Timestamp; - var end = frames.LastOrDefault()?.Timestamp; + var start = frames?.FirstOrDefault()?.Timestamp; + var end = frames?.LastOrDefault()?.Timestamp; return string.Format(Resources.URL_Simpsons_Result, site, content.Episode.Key, start, end); } diff --git a/src/FlawBOT/Services/Search/TwitchService.cs b/src/FlawBOT/Services/Search/TwitchService.cs index 90a6b494..3cd3892b 100644 --- a/src/FlawBOT/Services/Search/TwitchService.cs +++ b/src/FlawBOT/Services/Search/TwitchService.cs @@ -1,5 +1,4 @@ using System.Threading.Tasks; -using FlawBOT.Common; using TwitchLib.Api; using TwitchLib.Api.V5.Models.Search; @@ -7,10 +6,10 @@ namespace FlawBOT.Services { public class TwitchService : HttpHandler { - public static async Task GetTwitchDataAsync(string query) + public static async Task GetTwitchDataAsync(string token, string query) { var service = new TwitchAPI(); - service.Settings.ClientId = SharedData.Tokens.TwitchToken; + service.Settings.ClientId = token; return await service.V5.Search.SearchStreamsAsync(query).ConfigureAwait(false); } } diff --git a/src/FlawBOT/Services/Search/WorldService.cs b/src/FlawBOT/Services/Search/WeatherService.cs similarity index 62% rename from src/FlawBOT/Services/Search/WorldService.cs rename to src/FlawBOT/Services/Search/WeatherService.cs index a6788f71..4737101d 100644 --- a/src/FlawBOT/Services/Search/WorldService.cs +++ b/src/FlawBOT/Services/Search/WeatherService.cs @@ -1,27 +1,19 @@ using System.Net; using System.Threading.Tasks; -using FlawBOT.Common; using FlawBOT.Models; using FlawBOT.Properties; using Newtonsoft.Json; namespace FlawBOT.Services { - public class WorldService : HttpHandler + public class WeatherService : HttpHandler { - public static async Task GetIpLocationAsync(IPAddress query) - { - var result = await Http.GetStringAsync(string.Format(Resources.URL_IPStack, query)) - .ConfigureAwait(false); - return JsonConvert.DeserializeObject(result); - } - - public static async Task GetWeatherDataAsync(string query) + public static async Task GetWeatherDataAsync(string token, string query) { try { var results = await Http - .GetStringAsync(string.Format(Resources.URL_Weather, SharedData.Tokens.WeatherToken, query)) + .GetStringAsync(string.Format(Resources.URL_Weather, token, query)) .ConfigureAwait(false); return JsonConvert.DeserializeObject(results); } diff --git a/src/FlawBOT/Services/Search/WikipediaService.cs b/src/FlawBOT/Services/Search/WikipediaService.cs index 4037c54c..8df26996 100644 --- a/src/FlawBOT/Services/Search/WikipediaService.cs +++ b/src/FlawBOT/Services/Search/WikipediaService.cs @@ -1,5 +1,5 @@ -using WikipediaNet; -using WikipediaNet.Objects; +using Genbox.Wikipedia; +using Genbox.Wikipedia.Objects; namespace FlawBOT.Services { @@ -7,7 +7,7 @@ public class WikipediaService : HttpHandler { public static QueryResult GetWikipediaDataAsync(string query) { - var wikipedia = new Wikipedia {Limit = 5}; + var wikipedia = new WikipediaClient(); return wikipedia.Search(query); } } diff --git a/src/FlawBOT/Services/Search/YouTubeService.cs b/src/FlawBOT/Services/Search/YouTubeService.cs index c7a94d90..f1ae9033 100644 --- a/src/FlawBOT/Services/Search/YouTubeService.cs +++ b/src/FlawBOT/Services/Search/YouTubeService.cs @@ -6,7 +6,6 @@ using System.Text; using System.Threading.Tasks; using DSharpPlus.Entities; -using FlawBOT.Common; using FlawBOT.Models; using FlawBOT.Properties; using Google.Apis.Services; @@ -22,8 +21,8 @@ public YoutubeService() { YouTube = new YouTubeService(new BaseClientService.Initializer { - ApiKey = SharedData.Tokens.YouTubeToken, - ApplicationName = SharedData.Name + ApiKey = Program.Settings.Tokens.YouTubeToken, + ApplicationName = Program.Settings.Name }); } @@ -92,7 +91,7 @@ public async Task> GetMusicDataAsync(string term) string json; Http.BaseAddress = new Uri("https://www.googleapis.com/youtube/v3/search"); - Http.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", SharedData.Name); + Http.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", Program.Settings.Name); using (var req = await Http.GetAsync(uri)) await using (var res = await req.Content.ReadAsStreamAsync()) using (var sr = new StreamReader(res, Encoding.UTF8)) @@ -101,7 +100,7 @@ public async Task> GetMusicDataAsync(string term) } var jsonData = JObject.Parse(json); - var data = jsonData["items"].ToObject>(); + var data = jsonData["items"]?.ToObject>(); return data!.Select(x => new YouTubeData(x.Snippet.Title, x.Snippet.Author, x.Id.VideoId)); } diff --git a/src/FlawBOT/application.yml b/src/FlawBOT/application.yml index 9a3dd7a5..60b3de83 100644 --- a/src/FlawBOT/application.yml +++ b/src/FlawBOT/application.yml @@ -9,12 +9,12 @@ lavalink: password: "youshallnotpass" sources: youtube: true - bandcamp: true + bandcamp: false soundcloud: true twitch: true - vimeo: true - mixer: true - http: true + vimeo: false + mixer: false + http: false local: false bufferDurationMs: 400 youtubePlaylistLoadLimit: 6 # Number of pages at 100 each diff --git a/src/FlawBOT/config.json b/src/FlawBOT/config.json index 6d24d314..aa3b9b83 100644 --- a/src/FlawBOT/config.json +++ b/src/FlawBOT/config.json @@ -1,13 +1,18 @@ { - "prefix": ".", - "discord": null, - "steam": null, - "imgur": null, - "omdb": null, - "twitch": null, - "nasa": null, - "teamworktf": null, - "news": null, - "weather": null, - "youtube": null + "Name": "FlawBOT", + "Prefix": ".", + "ShardCount": 1, + "Lavalink": false, + "Tokens": { + "Discord": null, + "Steam": null, + "Imgur": null, + "OMDB": null, + "Twitch": null, + "NASA": null, + "TeamworkTF": null, + "News": null, + "Weather": null, + "YouTube": null + } } \ No newline at end of file