NATION

PASSWORD

FluffyCogs - a module for the Red Discord bot

Bug reports, general help, ideas for improvements, and questions about how things are meant to work.
User avatar
Darcania
Spokesperson
 
Posts: 103
Founded: Dec 29, 2014
Left-wing Utopia

FluffyCogs - a module for the Red Discord bot

Postby Darcania » Tue Feb 07, 2017 2:00 am

FluffyCogs is an open source set of features and commands that anyone may add to their instance of the Red Discord bot, which I highly recommend anyone who wants a bot on their server to check out.
FluffyCogs contains many different cogs and features, but for this post I will focus on its nationstates cog. For those interested, feel free to check out the approved repos list for other features that third party developers have added to the bot, including my own features.

Important Note: The below post is for the newest version of Red, version 3. This cog will not function with version 2 of Red. If you have the old version of Red, I recommend installing the new version as soon as you can. You can check which version you have by checking [p]info: if your discord.py version is 0.16.12 or less, then you have Red V2 installed.

Feel free to join the Red support server if you have any questions regarding Red. I will not be troubleshooting your installs here or anywhere except in that server.



  • What is Red?
    Red is a fully modular bot which comes with sets of features/commands that can be enabled/disabled to your liking, making it customizable exactly how you want.
    You can turn Red into a trivia bot, an admin bot, a music bot (...) or all of these together.
    Find it here: Install Documentation | Source Code
  • What is a module?
    Since Red is fully modular, you can pick and choose what modules ("repositories" / "repos") you want, and from each of those, you can pick and choose what specific functionalities ("cogs") you want! FluffyCogs is just that: a repo containing several cogs, including the nationstates cog and a few other useful or fun cogs I've developed.
For this post I will be focusing on the nationstates cog.

Please note for the below that [p] is shorthand - when actually running the commands, be sure to replace [p] with your bot's prefix. For example, my bot's prefix is an exclamation point, so instead of using [p]nation, I would use !nation.

The nationstates cog uses the sans pip library. Find its source code here.

The nationstates cog contains the following commands and features:
  1. [p]agent
    Sets the user agent to be used with the NationStates API. It's recommended to use your nation name and email, or some method of contacting you. The cog will add some information about the scripts you are using for ease of troubleshooting.
    If the agent isn't specified, it will default to your Discord username and hash. This will likely be removed in the future, so be sure to set your user agent yourself.
  2. [p]nation
    Shows general information on the specified nation.
    The Last Active field is adjusted to the timezone of the viewer automatically.
    Image
  3. [p]region
    Shows general information on the specified region.
    The Last Updated field is adjusted to the timezone of the viewer automatically.
    Image
  4. [p]wa / [p]ga / [p]sc
    The above all point to the same command, though the [p]sc version will point to the Security Council instead of the General Assembly.
    Gets general information on the specified resolution by ID.
    If no ID is provided, a summary of the current proposal, or the previous proposal if there is no current one, is returned.
    Various options are supported to get more information on the current resolution:
    • text - The resolution's text
    • votes - The total votes for and against
    • nations - The total nations for and against
    • delegates - The top ten Delegates for and against
    Note that the Nations and Delegates options are only available for at-vote resolutions.
    The Passed and Voting Ends fields are adjusted to the timezone of the viewer automatically.



    At-vote resolutionNo resolution at vote
    ImageImage
    Past resolutionOptions
    ImageImage

    As a bonus, the bot will also give a short summary of past resolutions when it sees GA#XXX or SC#XXX in a message. GAR#XXX and SCR#XXX is also supported.
    Currently there is no option to disable this, but a command to toggle this behavior is planned.
    Image
  5. [p]shard
    Returns raw data from the NationStates API according to various UNIX-style parameters.
    Useful for creating custom aliases to get specific data, e.g.: [p]alias add wacensus shard census --mode "score rrank" --scale "65 66" --nation *
    An asterisk (*) may be used to cause the command to consume the rest of the arguments at once, even without quotes.
    Image
  6. [p]ne
    Nations Endorsing (NE) the specified WA nation.
  7. [p]nec
    Nations Endorsing [Count] (NEC) the specified WA nation.
  8. [p]spdr
    Soft Power Disbursement Rating (SPDR, aka numerical Influence) of the specified nation.
  9. [p]nne
    Nations Not Endorsing (NNE) the specified WA nation.
  10. [p]nnec
    Nations Not Endorsing [Count] (NNEC) the specified WA nation.

If you're convinced and wish to install this cog, just use these three commands:
Code: Select all
[p]repo add FluffyCogs https://github.com/zephyrkul/FluffyCogs
[p]cog install FluffyCogs nationstates
[p]load nationstates
Last edited by Darcania on Mon Feb 18, 2019 6:34 pm, edited 10 times in total.

User avatar
Darcania
Spokesperson
 
Posts: 103
Founded: Dec 29, 2014
Left-wing Utopia

Postby Darcania » Mon Feb 27, 2017 8:31 pm

Just committed a massive update. I'll work on a changelog and the OP (<- Edit: That's been done now), but for now, to install, please do the following three commands, replacing [p] with your bot's prefix:

Code: Select all
[p]cog uninstall NationCogs nationstates
[p]cog uninstall NationCogs nationshards
[p]cog update


The only reason you have to uninstall the original two cogs is because they no longer exist, and Red does not delete old cogs if they are no longer in a repo. This shouldn't happen again, since the only reason I did that was to overhaul the framework in preparation for a future update.
Last edited by Darcania on Thu Apr 13, 2017 10:57 pm, edited 3 times in total.

User avatar
Darcania
Spokesperson
 
Posts: 103
Founded: Dec 29, 2014
Left-wing Utopia

Postby Darcania » Wed Mar 01, 2017 4:06 pm

Quick notice: There is a slight bug having to do with the command "[p]ga resolution" in the NSAssembly cog atm, having to do with the way the code splits the resolution into pages to avoid hitting the message length limit. While debugging, I also found another bug having to do with BBCode lists (namely, they are not parsed). I am currently working on a fix for these bugs; until then, avoid using "[p]ga resolution" (note that the embed for "[p]ga" will give you a link to the resolution at vote; just click the resolution title).

User avatar
Darcania
Spokesperson
 
Posts: 103
Founded: Dec 29, 2014
Left-wing Utopia

Postby Darcania » Thu Mar 02, 2017 1:04 pm

I note that at least one user had issues with updating due to the fact that they had already updated the bot before following the steps above. As a note, if, when using "[p]nation", you do not get a "Last Active" field at the bottom of the embed or you don't get a list of region tags when using "[p]region" or "[p]shard" returns a list that is indented using angle brackets > instead of whitespace, then you are still using the old cogs. Please follow the below steps:
  1. To make sure you update, run the commands listed two posts above this one. If the first command ([p]cog uninstall NationCogs nationstates) returns "That cog isn't available from that repo.", then you have already updated; follow the steps below. If it instead returns the following:
    That module file doesn't exist. I will not turn off autoloading at start just in case this isn't supposed to happen.
    Module disabled.
    Cog successfully uninstalled.

    Then ignore the "error" saying that file doesn't exist, the uninstall still worked (this is a bug with Red). In such a case, follow the instructions two posts above this one.
  2. If the bot returned "That cog isn't available from that repo.", then do the following:
    Code: Select all
    [p]unload nationstates
    [p]unload nationshards
  3. Next, find your Red folder (wherever you initially installed it). Open it, and in the /cogs/ folder, find "nationstates.py" and "nationshards.py". Delete these two, but do not delete any other files or folders in that folder.
  4. Then, go back to your Red folder and find the /data/ folder. In there, find a folder named /nationstates/. You can either delete that folder (in which case you will have to re-set your user agent) or rename it to /nsapi/, which will carry over your previously set user agent.
  5. Next, do the following commands:
    Code: Select all
    [p]cog install NationCogs nsapi
    (say yes when the bot prompts you)
    [p]cog install NationCogs nsstandard
    (say yes when the bot prompts you)
    [p]cog list NationCogs
  6. That last command will give you a list of all cogs that you can install from NationCogs. Feel free to install whichever ones you want using "[p]cog install NationCogs <cog name>".
  7. Congratulations, you're fully updated!
My apologies again for making this update so complicated, but as I said above it was necessary for a future framework update. This will be the last time this happens; I promise.


Also, on a separate note, the bug I mentioned above was caused by an issue with Red. I've informed the developer and suggested a bugfix through a pull request on their GitHub, but it has not yet been implemented. In the meantime, I am working on the other bug having to do with not parsing lists.

User avatar
Darcania
Spokesperson
 
Posts: 103
Founded: Dec 29, 2014
Left-wing Utopia

Postby Darcania » Thu Apr 06, 2017 4:34 pm

Just committed a new update. If the nation isn't found, the bot will now link you to the Boneyard for the given nation name. To update:
Code: Select all
[p]cog update

Much simpler this time.

User avatar
Darcania
Spokesperson
 
Posts: 103
Founded: Dec 29, 2014
Left-wing Utopia

Postby Darcania » Thu Apr 13, 2017 4:37 pm

New update, same process as above. Changelog coming later tonight.
Edit: Changelog added.
Last edited by Darcania on Thu Apr 13, 2017 10:56 pm, edited 1 time in total.

User avatar
Sad-States
Envoy
 
Posts: 203
Founded: Oct 04, 2013
Ex-Nation

Postby Sad-States » Fri Apr 14, 2017 10:25 am

Good job!
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- Former Magister in The East Pacific | Former Officer within the EPSA | Former Officer of HR in The Rejected Realms | -
Proud Founder of The Audax Order
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

User avatar
Darcania
Spokesperson
 
Posts: 103
Founded: Dec 29, 2014
Left-wing Utopia

Postby Darcania » Mon May 08, 2017 7:01 pm

FYI, it seems there's a person going around and advertising on all sorts of NS Discord servers asking if they'd like to have his bot due to a specific functionality it has (namely, verifying that a member controls a nation in a region and giving a role accordingly).

If such functionality is desired, it would be quite easy for me to make and add to my cogs. It also won't require bringing in some random person's bot; like the other cogs, you would simply install it on your own bot.

I note that bringing in a bot that doesn't belong to someone you know is a security risk; only popular, public bots like Squid are safe to invite when you don't know the owner.

Feel free to let me know if you'd be interested in such functionality.

Edit: Forgot to mention, the person going around is austinhuang#1076. He was also caught in a blatant lie in TNP's server, so take of that what you will.
Last edited by Darcania on Mon May 08, 2017 7:10 pm, edited 1 time in total.

User avatar
Caelapes
Ambassador
 
Posts: 1491
Founded: Apr 30, 2007
Liberal Democratic Socialists

Postby Caelapes » Mon May 08, 2017 7:09 pm

Darcania wrote:FYI, it seems there's a person going around and advertising on all sorts of NS Discord servers asking if they'd like to have his bot due to a specific functionality it has (namely, verifying that a member controls a nation in a region and giving a role accordingly).

If such functionality is desired, it would be quite easy for me to make and add to my cogs. It also won't require bringing in some random person's bot; like the other cogs, you would simply install it on your own bot.

I note that bringing in a bot that doesn't belong to someone you know is a security risk; only popular, public bots like Squid are safe to invite when you don't know the owner.

Feel free to let me know if you'd be interested in such functionality.

Are there other Discord bots besides Lenin that do this? Because I'm not advertising on any NS Discord server about Lenin.
     
The Rose Commune of Caelapes
Ego vero custos fratris mei sum.
aka Misley

User avatar
Darcania
Spokesperson
 
Posts: 103
Founded: Dec 29, 2014
Left-wing Utopia

Postby Darcania » Mon May 08, 2017 7:12 pm

Caelapes wrote:Are there other Discord bots besides Lenin that do this? Because I'm not advertising on any NS Discord server about Lenin.

He stated that he hasn't coded the bot yet, he's just gauging interest.

User avatar
Malachor VIII
Lobbyist
 
Posts: 15
Founded: Dec 19, 2016
New York Times Democracy

Postby Malachor VIII » Mon May 08, 2017 7:13 pm

Caelapes wrote:Are there other Discord bots besides Lenin that do this? Because I'm not advertising on any NS Discord server about Lenin.

The person advertising said that the bot wasn't created yet.
Delegate of Merridel

User avatar
Darcania
Spokesperson
 
Posts: 103
Founded: Dec 29, 2014
Left-wing Utopia

Postby Darcania » Mon May 08, 2017 7:23 pm

Darcania wrote:
Caelapes wrote:Are there other Discord bots besides Lenin that do this? Because I'm not advertising on any NS Discord server about Lenin.

He stated that he hasn't coded the bot yet, he's just gauging interest.

Though I also note that he stated later that his bot is in 500 servers (this being the lie he was caught in above).

User avatar
Caelapes
Ambassador
 
Posts: 1491
Founded: Apr 30, 2007
Liberal Democratic Socialists

Postby Caelapes » Mon May 08, 2017 7:29 pm

Gotcha.

If it helps you figure out how desirable the functionality is, the concept has been fairly well received among the NSLeft. We authenticate nations upon registration on our interregional forum, which we tie to Discord through our closed-source bot Lenin, which is written in Python and based on the MusicBot framework.

Of four existing regional servers (five total, counting the interregional hub server) among the six NSLeft member regions, three regional servers and the interregional hub server use Lenin's authentication system, which has linked 170 separate Discord accounts to a forum account and its associated nations. Lenin's authentication is fairly basic, however, and doesn't check to see if the user has claimed a nation that resides in the particular region's server to provide special role access - each server has a general "verified" role that all users are granted, with special roles defined and granted manually for regional government or server moderators.

I'd be happy to share what I've put together for Lenin you'd like, although it's really pretty use-specific and may not be useful in a more generalized fashion.
     
The Rose Commune of Caelapes
Ego vero custos fratris mei sum.
aka Misley

User avatar
The Cafes
Lobbyist
 
Posts: 14
Founded: May 04, 2017
Ex-Nation

Postby The Cafes » Mon May 08, 2017 7:46 pm

Excuse me for a moment. First I am implanting this as a function of my existing bot which is in 500+ servers (Proof, I wouldn't link it directly). Second, even you value the safety of data which I acknowledge your point, users Still Need to verify themselves in each server, unlike RoVer (Public verification Bot for Roblox) which only require 1 verification per user.
And btw, do all Discord server owners know the bots' owner when adding a public bot? Oh, and you mentioned my name. Thank you for making us privileged.

User avatar
Darcania
Spokesperson
 
Posts: 103
Founded: Dec 29, 2014
Left-wing Utopia

Postby Darcania » Mon May 08, 2017 8:15 pm

Glad you failed to read what I said, The Cafes, maybe one day you'll have passable reading comprehension.


Thanks for the offer, Caelapes, but I think my use-case will be sufficiently different to where your code won't be all too useful. Mostly the code will consist of simply guiding the user through the verification process and making a couple HTTP GET requests at the most.

(Quick note: The Registration page of the forum you linked appears to have an issue: the verification page refuses to load if it's embedded. Something you may want to fix or point out to those who can.)

User avatar
The Cafes
Lobbyist
 
Posts: 14
Founded: May 04, 2017
Ex-Nation

Postby The Cafes » Mon May 08, 2017 8:20 pm

Darcania wrote:Glad you failed to read what I said, The Cafes, maybe one day you'll have passable reading comprehension.


Thanks for the offer, Caelapes, but I think my use-case will be sufficiently different to where your code won't be all too useful. Mostly the code will consist of simply guiding the user through the verification process and making a couple HTTP GET requests at the most.

(Quick note: The Registration page of the forum you linked appears to have an issue: the verification page refuses to load if it's embedded. Something you may want to fix or point out to those who can.)

Alright, I'll accept the challenge and code it. It's just one more function with Verify Login and some database. By the way, I'm pretty sure That you Can't Read sarcasm.

User avatar
Caelapes
Ambassador
 
Posts: 1491
Founded: Apr 30, 2007
Liberal Democratic Socialists

Postby Caelapes » Tue May 09, 2017 4:17 am

Darcania wrote:Thanks for the offer, Caelapes, but I think my use-case will be sufficiently different to where your code won't be all too useful. Mostly the code will consist of simply guiding the user through the verification process and making a couple HTTP GET requests at the most.

Understandable!

Darcania wrote:(Quick note: The Registration page of the forum you linked appears to have an issue: the verification page refuses to load if it's embedded. Something you may want to fix or point out to those who can.)

(Did you check with an incognito window? The login page won't load if embedded, as a safety measure to make sure folks don't log in with their NS password on another website. It should work properly if you're logged in to NS—if not, it might be an issue with cookies.)
Last edited by Caelapes on Tue May 09, 2017 2:06 pm, edited 1 time in total.
     
The Rose Commune of Caelapes
Ego vero custos fratris mei sum.
aka Misley

User avatar
Darcania
Spokesperson
 
Posts: 103
Founded: Dec 29, 2014
Left-wing Utopia

Postby Darcania » Tue May 09, 2017 10:12 am

Caelapes wrote:(Did you check with an incognito window? The login page won't load if embedded, as a safety measure to make sure folks don't log in with their NS password on another website. It should work properly if you're logged in to NS—if not, it might be an issue with cookies.)

No, I was using Chrome normally (not incognito) with a logged in nation (this one).

User avatar
Darcania
Spokesperson
 
Posts: 103
Founded: Dec 29, 2014
Left-wing Utopia

Postby Darcania » Fri Aug 11, 2017 10:10 am

As a quick update on this, since it's been a while - there will likely be one more update to these cogs (it unfortunately will not be verification; there is currently an issue with the way I connect with the API atm that prevents me from doing that) before it will be frozen in preparation for a couple bigger changes.

  1. I'm making my own API wrapper, since pynationstates, while good, isn't really what I'm looking for for this cog. This one will hopefully be faster, more asynchronous-friendly, and more memory-efficient than pynationstates as it currently stands, and won't rely on any third-party libraries besides aiohttp (which Red already requires; pynationstates currently requires BeautifulSoup4, requests, xmltodict, and ezurl, as well as being a third-party library itself). Also, this will allow for more features, including verification API support.
  2. When that's done, I will add the verification cog.
  3. The new cogs will support Red V3 when that comes out, and will not be compatible with the current version of Red (V2). Note that V3 is still a ways away from completion, so you won't have to worry about the transition for a while.
    As a small note, V3 won't necessarily read your data that you have under Red V2. At most this means you'll just have to set your user agent again when NSCogs for V3 is released.
  4. The cogs will likely all be collapsed to one single cog, since most everyone uses all the cogs at once anyway and that will make managing the API usage significantly easier.
  5. This repo (NationCogs) may end up left as it is (feature-locked and all that) while V3 cogs will move to a separate repo, which will hopefully have some fun non-NS cogs in it as well (NationCogs has some of those already, but I plan to add more, larger non-NS cogs later on).

Please feel free to make any feature requests or let me know any ideas you have for the future development of these cogs, please feel free to post below, write me a telegram, post in the associated V3 Github issue, or even find me on Discord (Zephyrkul#1795).

As well, an important note: You may or may not have heard recently about changes to Discord Developer API's terms of service. I suggest ignoring that and not worrying about it, since the Discord community and several Discord developers are strongly against it, and the TOS is generally stricter than what is actually enforced (like most TOS's).
Last edited by Darcania on Fri Aug 11, 2017 10:20 am, edited 1 time in total.

User avatar
Darcania
Spokesperson
 
Posts: 103
Founded: Dec 29, 2014
Left-wing Utopia

Postby Darcania » Mon Oct 30, 2017 2:10 pm

I have activated a flag to show Z-Day statistics on nations and regions in the NSStandard cog. Please update your cogs to see this new functionality.

User avatar
Darcania
Spokesperson
 
Posts: 103
Founded: Dec 29, 2014
Left-wing Utopia

Postby Darcania » Wed Nov 01, 2017 8:03 am

The Z-Day flag has been deactivated. The Z-Day functions still work otherwise, however, so if you want to keep Z-Day stats up just delay updating your cogs. You'll have to update eventually, though, just like you'll have to move on from the catastrophe of a 20.4% survival rate.

User avatar
Darcania
Spokesperson
 
Posts: 103
Founded: Dec 29, 2014
Left-wing Utopia

Postby Darcania » Fri Oct 19, 2018 11:24 pm

With the impending update to Red V3, NationCogs has been archived and is no longer supported, though Red will still be able to install it. No further features, enhancements, or bugfixes will be added to that repo.

My repo of cogs for Red V3 may be found here: https://github.com/zephyrkul/FluffyCogs
Note that V3 cogs will not function on the old version of Red, or vice versa.

The nationstates cog there is not yet complete but the new backend I wrote for it (now entirely custom rather than using the now unsupported pynationstates) will allow me to utilize more of the API's features, so stay tuned. There were some minor changes to the commands I updated, except [p]shard, which now prints the XML directly and also accepts UNIX-style arguments to allow further tuning. For example: [p]shard --nation "Great Bights Mum" census --scale "65 66" --mode score

Future plans include porting over the rest of the commands, adding auto-role functionality based on nation, and including the two missing FT-style commands, neb and nneb, that I never finished for NationCogs. The custom asynchronous backend may also be moved to its own repo to become a separate PyPi library, but as aionationstates already exists it's unlikely I'll decide to do so.

A thread specifically for the NationStates cog in the FluffyCogs repo may or may not be made in the future depending on if I have the time and effort to spare.

Until such time as that thread exists you may continue to use this thread or TG me. Alternate contact details are in the above GitHub repo's readme.
Last edited by Darcania on Fri Oct 19, 2018 11:27 pm, edited 1 time in total.

User avatar
Darcania
Spokesperson
 
Posts: 103
Founded: Dec 29, 2014
Left-wing Utopia

Postby Darcania » Sun Oct 21, 2018 2:58 pm

LUL, not soon after the above the alpha rewrite of pynationstates is released. Oh well, I've needed to use a more async-friendly library from the start anyway.

User avatar
Darcania
Spokesperson
 
Posts: 103
Founded: Dec 29, 2014
Left-wing Utopia

Postby Darcania » Fri Jan 18, 2019 7:38 pm

Darcania wrote:The custom asynchronous backend may also be moved to its own repo to become a separate PyPi library, but as aionationstates already exists it's unlikely I'll decide to do so.

I ended up seperating this backend out to its own repo for ease of testing. It can be found on PyPI here: https://pypi.org/project/sans/
It's still in alpha (so there's likely to be plenty of bugs) and mainly used for my cogs but if anyone else is interested they can use it. Note that it's designed with concurrency (i.e. async, threads) in mind, so while it can be run synchronously in a script there's some significant overhead due to the concurrency-friendly model, so it's recommended to use Dolph's pynationstates for simple scripts.

Also, if you had my cogs downloaded on V3 before this change and are getting ImportErrors after updating, run this command: [p]pipinstall sans
(replace [p] with your prefix)
V3 doesn't record changes to a cog's requirements if the cogs were already installed, so that command will install the requirement for you.

User avatar
Darcania
Spokesperson
 
Posts: 103
Founded: Dec 29, 2014
Left-wing Utopia

Postby Darcania » Mon Jan 28, 2019 7:15 pm

Good news - Red V3 has an official, stable release now, and with my port of NSEndorse now up on FluffyCogs (my repo for V3), NS support for the latest Red is now also fully set up.

Anyone looking for a bot for their NS Discord server should now look at Red V3 rather than the old version of Red - you can find install instructions for V3 here: https://red-discordbot.readthedocs.io/en/v3-develop/

Anyone still using V2 (which you are using unless you specifically installed V3) can continue using it if they wish, but every part of it - from NationCogs, to the bot itself, to the library the bot uses to connect to Discord - are no longer actively supported beyond bugfixes for the latter two. If you haven't tried V3 before, I highly recommend it, much better than the old Red, just keep in mind that it's a brand new bot, so you'll have to install it fresh. It does support some amount of data conversion from V2, but not every cog supports that feature.

Edit: Oh, and I forgot to add that the v3 version provides links to a nation's deck and its card with the [p]nation command. Something something feature-rich upgrade.
Last edited by Darcania on Mon Jan 28, 2019 7:20 pm, edited 1 time in total.

Next

Advertisement

Remove ads

Return to Technical

Who is online

Users browsing this forum: No registered users

Advertisement

Remove ads