-
-
Notifications
You must be signed in to change notification settings - Fork 750
Removed API dependency for Tags #803
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
9fd7b08
Added all the tag files in resources and modified cogs/tags.py file t…
RohanJnr f256346
added white spaces on statements before bullet points for proper rend…
RohanJnr fe31808
Re-corrected the lines which I had changed by mistake
RohanJnr d583e9b
Merge branch 'master' into tags_overhaul
RohanJnr 1b56868
Caching all the tags when the bot has loaded(caching only once) inste…
RohanJnr a7ad0b7
Merge branch 'tags_overhaul' of https://github.com/RohanJnr/bot into …
RohanJnr 1c7b2d8
Use "pathlib" instead of "os" module and context manager
RohanJnr 073fdf1
Convert "get_tags()" and "_get_tag()" to sync functions
RohanJnr c624c25
Merge branch 'master' into tags_overhaul
sco1 564690f
Update tag files for new linting hooks
sco1 4662cfd
Update ytdl tag to the new YouTube ToS
Akarys42 f2d10e4
remove repetitive file search
RohanJnr 9bc6744
Merge branch 'master' into tags_overhaul
RohanJnr 55effb3
convert get_tags() method to staticmethod
RohanJnr d56639c
Merge branch 'tags_overhaul' of https://github.com/RohanJnr/bot into …
RohanJnr e9ae8a8
Remove line that calls get_tags() method
RohanJnr 52ed9aa
Tags: use constant for command prefix in embed footer
MarkKoz eeaccea
Tags: add restrictions 1 & 9 from YouTube ToS to ytdl tag
MarkKoz 5865126
convert _get_tags_via_content() method to non-async
RohanJnr 156492c
Merge branch 'tags_overhaul' of https://github.com/RohanJnr/bot into …
RohanJnr 520c730
not awaiting _get_tags_via_content() method as it is non-async
RohanJnr 8eea9c3
Fixed tag search via contents, any keywords.
ikuyarihS File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| `*args` and `**kwargs` | ||
|
|
||
| These special parameters allow functions to take arbitrary amounts of positional and keyword arguments. The names `args` and `kwargs` are purely convention, and could be named any other valid variable name. The special functionality comes from the single and double asterisks (`*`). If both are used in a function signature, `*args` **must** appear before `**kwargs`. | ||
|
|
||
| **Single asterisk** | ||
| `*args` will ingest an arbitrary amount of **positional arguments**, and store it in a tuple. If there are parameters after `*args` in the parameter list with no default value, they will become **required** keyword arguments by default. | ||
|
|
||
| **Double asterisk** | ||
| `**kwargs` will ingest an arbitrary amount of **keyword arguments**, and store it in a dictionary. There can be **no** additional parameters **after** `**kwargs` in the parameter list. | ||
|
|
||
| **Use cases** | ||
| • **Decorators** (see `!tags decorators`) | ||
| • **Inheritance** (overriding methods) | ||
| • **Future proofing** (in the case of the first two bullet points, if the parameters change, your code won't break) | ||
| • **Flexibility** (writing functions that behave like `dict()` or `print()`) | ||
|
|
||
| *See* `!tags positional-keyword` *for information about positional and keyword arguments* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| Asking good questions will yield a much higher chance of a quick response: | ||
|
|
||
| • Don't ask to ask your question, just go ahead and tell us your problem. | ||
| • Don't ask if anyone is knowledgeable in some area, filtering serves no purpose. | ||
| • Try to solve the problem on your own first, we're not going to write code for you. | ||
| • Show us the code you've tried and any errors or unexpected results it's giving. | ||
| • Be patient while we're helping you. | ||
|
|
||
| You can find a much more detailed explanation [on our website](https://pythondiscord.com/pages/asking-good-questions/). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| **Classes** | ||
|
|
||
| Classes are used to create objects that have specific behavior. | ||
|
|
||
| Every object in python has a class, including `list`s, `dict`ionaries and even numbers. Using a class to group code and data like this is the foundation of Object Oriented Programming. Classes allow you to expose a simple, consistent interface while hiding the more complicated details. This simplifies the rest of your program and makes it easier to separately maintain and debug each component. | ||
|
|
||
| Here is an example class: | ||
|
|
||
| ```python | ||
| class Foo: | ||
| def __init__(self, somedata): | ||
| self.my_attrib = somedata | ||
|
|
||
| def show(self): | ||
| print(self.my_attrib) | ||
| ``` | ||
|
|
||
| To use a class, you need to instantiate it. The following creates a new object named `bar`, with `Foo` as its class. | ||
|
|
||
| ```python | ||
| bar = Foo('data') | ||
| bar.show() | ||
| ``` | ||
|
|
||
| We can access any of `Foo`'s methods via `bar.my_method()`, and access any of `bar`s data via `bar.my_attribute`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| Although most methods are tied to an _object instance_, it can sometimes be useful to create a method that does something with _the class itself_. To achieve this in Python, you can use the `@classmethod` decorator. This is often used to provide alternative constructors for a class. | ||
|
|
||
| For example, you may be writing a class that takes some magic token (like an API key) as a constructor argument, but you sometimes read this token from a configuration file. You could make use of a `@classmethod` to create an alternate constructor for when you want to read from the configuration file. | ||
| ```py | ||
| class Bot: | ||
| def __init__(self, token: str): | ||
| self._token = token | ||
|
|
||
| @classmethod | ||
| def from_config(cls, config: dict) -> Bot: | ||
| token = config['token'] | ||
| return cls(token) | ||
|
|
||
| # now we can create the bot instance like this | ||
| alternative_bot = Bot.from_config(default_config) | ||
|
|
||
| # but this still works, too | ||
| regular_bot = Bot("tokenstring") | ||
| ``` | ||
| This is just one of the many use cases of `@classmethod`. A more in-depth explanation can be found [here](https://stackoverflow.com/questions/12179271/meaning-of-classmethod-and-staticmethod-for-beginner#12179752). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| Discord has support for Markdown, which allows you to post code with full syntax highlighting. Please use these whenever you paste code, as this helps improve the legibility and makes it easier for us to help you. | ||
|
|
||
| To do this, use the following method: | ||
|
|
||
| \```python | ||
| print('Hello world!') | ||
| \``` | ||
|
|
||
| Note: | ||
| • **These are backticks, not quotes.** Backticks can usually be found on the tilde key. | ||
| • You can also use py as the language instead of python | ||
| • The language must be on the first line next to the backticks with **no** space between them | ||
|
|
||
| This will result in the following: | ||
| ```py | ||
| print('Hello world!') | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| **Decorators** | ||
|
|
||
| A decorator is a function that modifies another function. | ||
|
|
||
| Consider the following example of a timer decorator: | ||
| ```py | ||
| >>> import time | ||
| >>> def timer(f): | ||
| ... def inner(*args, **kwargs): | ||
| ... start = time.time() | ||
| ... result = f(*args, **kwargs) | ||
| ... print('Time elapsed:', time.time() - start) | ||
| ... return result | ||
| ... return inner | ||
| ... | ||
| >>> @timer | ||
| ... def slow(delay=1): | ||
| ... time.sleep(delay) | ||
| ... return 'Finished!' | ||
| ... | ||
| >>> print(slow()) | ||
| Time elapsed: 1.0011568069458008 | ||
| Finished! | ||
| >>> print(slow(3)) | ||
| Time elapsed: 3.000307321548462 | ||
| Finished! | ||
| ``` | ||
|
|
||
| More information: | ||
| • [Corey Schafer's video on decorators](https://youtu.be/FsAPt_9Bf3U) | ||
| • [Real python article](https://realpython.com/primer-on-python-decorators/) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| **Dictionary Comprehensions** | ||
|
|
||
| Like lists, there is a convenient way of creating dictionaries: | ||
| ```py | ||
| >>> ftoc = {f: round((5/9)*(f-32)) for f in range(-40,101,20)} | ||
| >>> print(ftoc) | ||
| {-40: -40, -20: -29, 0: -18, 20: -7, 40: 4, 60: 16, 80: 27, 100: 38} | ||
| ``` | ||
| In the example above, I created a dictionary of temperatures in Fahrenheit, that are mapped to (*roughly*) their Celsius counterpart within a small range. These comprehensions are useful for succinctly creating dictionaries from some other sequence. | ||
|
|
||
| They are also very useful for inverting the key value pairs of a dictionary that already exists, such that the value in the old dictionary is now the key, and the corresponding key is now its value: | ||
| ```py | ||
| >>> ctof = {v:k for k, v in ftoc.items()} | ||
| >>> print(ctof) | ||
| {-40: -40, -29: -20, -18: 0, -7: 20, 4: 40, 16: 60, 27: 80, 38: 100} | ||
| ``` | ||
|
|
||
| Also like list comprehensions, you can add a conditional to it in order to filter out items you don't want. | ||
|
|
||
| For more information and examples, check [PEP 274](https://www.python.org/dev/peps/pep-0274/) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.