Can someone please tell me how to format the Default help command in discord.py
I already know how to change the description however, I want to be able to change the width and sort them alphabetically.
Thanks for any help
:)
You can override certain functions in the default help command. Below is an official example on how to set this up initially:
class MyHelpCommand(commands.MinimalHelpCommand):
def get_command_signature(self, command):
return '{0.clean_prefix}{1.qualified_name} {1.signature}'.format(self, command)
class MyCog(commands.Cog):
def __init__(self, bot):
self._original_help_command = bot.help_command
bot.help_command = MyHelpCommand()
bot.help_command.cog = self
def cog_unload(self):
self.bot.help_command = self._original_help_command
The example above overrides the implementation of get_command_signature.
As you can see, you're supposed to create a new HelpCommand class and change the functions. Stuff that you don't want to change can just be left untouched, you don't have to copy-paste the existing code in there.
To see what a HelpCommand and MinimalHelpCommand can do (to override the methods), I suggest scrolling through the relevant API Documentation.
This way, in case there's something that you don't like about the default help, you can just change it's behaviour and fix it yourself. In your case, you're gonna want to sort the list of commands before adding them to the codeblock.
I recommend flicking through the default implementation's functions to see what you have to change about it. In your case, send_bot_help, send_cog_help, send_command_help, and send_group_help will need the lists sorted.
Related
I need to process a couple of boolean options, and I am trying to do it like it is usually done in C:
DICT = 0x000020000
FILTER = 0x000040000
HIGH = 0x000080000
KEEP = 0x000100000
NEXT = 0x000200000
I can now assign arbitrary options to a Integer variable, and test for them:
action if (opts & HIGH|KEEP) != 0
But this looks ugly and gets hard to read. I would prefer writing it like
action if opts.have HIGH|KEEP
This would require to load have method onto Integer class.
The question now is: where would I do that, in order to keep this method contained to the module where those options are used and the classes that include this module? I don't think it's a good idea to add it globally, as somebody might define another have somewhere.
Or, are there better approaches, for the general task or for the given use-case? Adding a separate Options class looks like overkill - or should I?
You can use anybits?:
action if opts.anybits?(HIGH|KEEP)
The methods returns true if any bits from the given mask are set in the receiver, and false otherwise.
I am using paper_trail for undo/redo functionality in my site and am having a problem when I call reify.save on a version in that on save and new PaperTrail::Version gets created.
Is there a way to turn off PaperTrail during the saving of a reified object?
I understand that PaperTrail.enabled = false is possible, but I don't want other changes being made a the same time to not be recorded.
My ideal solution would be something along the lines of:
PaperTrail.disable { version.reify.save }
I once accomplished something similar by mixing in something like this:
def without_papertrail
PaperTrail.disable
yield if block_given?
PaperTrail.enable
end
Then you can do something similar to your objective
without_papertrail { version.reify.save }
You can disable paper trail for a particular model, using either of two syntaxes:
m = MyModel.find(123)
m.paper_trail.without_versioning do
# No versioning of `m` happens in this block
end
Note: Since it is called on a model instance, it seems as though this might naturally disable versioning on just that instance, but this syntax disables versioning on the entire model.
The other syntax:
MyModel.paper_trail.disable
# No versioning of MyModel happens here
MyModel.paper_trail.enable
As of today, gem version 10.3.0, the correct way to achieve this is, as per the gem documentation:
PaperTrail.request.disable_model(Banana)
# changes to Banana model do not create versions,
# but eg. changes to Kiwi model do.
PaperTrail.request.enable_model(Banana)
from the readme: https://github.com/paper-trail-gem/paper_trail#7-testing
PaperTrail.enabled = false
Just like I can pull in the currently selected text into a snippet using the $TM_SELECTED_TEXT, is there any way I can retrieve text from my code like the method name or class name containing the current caret position?
This'd be super useful for quickly creating useful log messages.
So, if I had some, say, JavaScript code (with | representing the cursor/caret location):
function doSomething() {
somethingElse();
|
}
I'd love to be able to spit out doSomething via a snippet.
Something like,
console.log($TM_CURRENT_METHOD_NAME + "() $1");
Is something like this possible?
In my fork of the Ember bundle, I put this script in Support/bin/camelize_filename:
#!/usr/bin/env ruby
c=%w{config helpers mixins controllers models routes templates views}.join('|')
r = %r{.*/(?:#{c})/(.*)\.js}
puts ENV['TM_FILEPATH'].sub(%r{.*/(?:#{c})/(.*)\.js},'\1').
gsub(/(?:_|(\/)|^)([a-z\d]*)/){|s| "#{$1}#{$2.capitalize}" }.gsub('/','')
Then I use it in snippets thusly:
console.groupCollapsed("`camelize_filename`#model");
You could adapt this for other frameworks by adapting the regex to match which directory segments belong in a class's namespace and which do not, and changing gsub('/','') if the language you are interested uses a namespace delimiter like '::'.
I'm automating a site that has a page with a list of options selected by a radio button. When selecting one of the radios, a text field and a select list are presented.
I created a file (test_contracting.rb) that is the one through which I execute the test (ruby test_contracting.rb) and some other classes to represent my page.
On my class ContractPage, I have the following element declaration:
checkbox(:option_sub_domain, :id => "option_sub_domain")
text_field(:domain, :id => "domain_text")
select_list(:tld, :id => "domain_tld")
I've created in the ContractPage a method that sets the configuration of the domain like this:
def configure_domain(config={})
check_option_sub_domain
domain = config[:domain]
tld = config[:tld]
end
When I call the method configure_domain from the test_contracting.rb, it selects the radio button, but it doesn't fill the field with the values. The params are getting into the method correctly. I've checked it using "puts". Even if I change the params to a general string like "bla" it doesnt work. The annoying point is that if on test_contracting.rb I call the exact same components, it works.
my_page_instance = ContractPage.new(browser)
my_page_instance.domain = "bla"
my_page_instance.tld = ".com"
What I found to work was to in the configure_domain method, implement the following:
domain_element.value = config[:domain]
tld_element.send_keys config[:locaweb_domain]
Then it worked.
The documentation for the PageObjects module that I'm using as reference can be found here: http://rubydoc.info/github/cheezy/page-object/master/PageObject/Accessors#select_list-instance_method
Do you guys have any explation on why the method auto generated by the pageobject to set the value of the object didnt work in this scope/context ?
By the way, a friend tried the same thing with Java and it failed as well.
In ruby all equals methods (methods that end with the = sign) need to have a receiver. Let me show you some code that will demonstrate why. Here is the code that sets a local variable to a value:
domain = "blah"
and here is the code that calls the domain= method:
domain = "blah"
In order for ruby to know that you are calling a method instead of setting a local variable you need to add a receiver. Simply change your method above to this and it will work:
def configure_domain(config={})
check_option_sub_domain
self.domain = config[:domain]
self.tld = config[:tld]
end
I'm pretty new to this world of Selenium and page objects but maybe one of my very recent discoveries might help you.
I found that that assignment methods for the select_list fields only worked for me once I started using "self" in front. This is what I have used to access it within my page object code. e.g., self.my_select_list="my select list value"
Another note - The send_keys workaround you mention is clever and might do the trick for a number of uses, but in my case the select list values are variable and may have several options starting with the same letter.
I hope something in here is useful to you.
UPDATE (Jan 3/12)
On diving further into the actual Ruby code for the page object I discovered that the select_list set is also using send_keys, so in actuality I still have the same limitation here as the one I noted using the send_keys workaround directly. sigh So much to learn, so little time!
I am trying to implement QLineEdit's text which is all capital letters no matter what user types in. I have found several solutions, none of them working in Ruby. In brief I have QLineEdit object searchEdit and this code:
class UpcaseValidator < Qt::Validator
def validate(input,pos)
input.upcase!
Qt::Validator::Acceptable
end
end
...
def initialize(parent = nil)
uppercaseValidator = UpcaseValidator.new;
searchEdit.setValidator(uppercaseValidator)
...
The validate method gets triggered correctly whenever user types in the input field, but it is not getting uppercased. Seems to me that changing input variable within validate does not get propagated back to the searchEdit object.
Thanks for any help, even pointing me out to some good docs about Qt Ruby bindings.
QValidator has a method called 'fixup()', which will probably do what you want :)