This commit is contained in:
NaiJi ✨ 2020-12-14 15:59:17 +03:00
commit 2d8b03d65b
7 changed files with 2442 additions and 0 deletions

24
LICENSE Normal file
View File

@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <https://unlicense.org>

18
README.md Normal file
View File

@ -0,0 +1,18 @@
# morrowsay-bot
Just a bot which posts random generic quotes to your Mastodon timeline!
Currently posting on: https://social.inex.rocks/@MorrowindNPCbot
### How to run ###
* For posting you can use already pre-saved quotes from the repository. If you want "your own", you can...
* ...download quotes:
```bash
python3 loadquotes.py
```
* To make a single post with a random quote from the gotten file, run `post.py`
* Don't forget to setup your bot account, get access tokens and establish the environment around it. I am not providing any instructions of how to do it, since all the steps are different and depend on what, where and how you want to run the bot.
* That's all!
![alt text](https://i.imgur.com/3ao6VLt.png)

30
loadquotes.py Normal file
View File

@ -0,0 +1,30 @@
import sys
import os.path as op
from urllib.parse import urlparse
from pprint import pprint
import requests
from bs4 import BeautifulSoup
# --------------------------------------------------
URL = "https://elderscrolls.fandom.com/wiki/Generic_Dialogue_(Morrowind)"
def main():
print('REQUEST ' + URL)
resp = requests.get(URL)
soup = BeautifulSoup(resp.text, 'lxml')
print('DOWNLOADING')
res = [icont.string for icont in soup('i') if icont.string is not None]
with open('quotes.dat', 'w', encoding='utf-8') as file:
for quote in res:
print(quote, file=file)
print('YAY SUCCESS!\n\n! ! ! Now don\'t forget to run replacevars.py ! ! !')
if __name__ == '__main__':
sys.exit(main())

29
post.py Normal file
View File

@ -0,0 +1,29 @@
import sys
import random
import datetime
import os.path as op
from pprint import pprint
import requests
from mastodon import Mastodon
# --------------------------------------------------
def main():
mastodon = Mastodon(
access_token = 'token.dat',
api_base_url = 'https://social.inex.rocks/'
)
with open('quotes.dat', 'r', encoding='utf-8') as file:
data = file.readlines()
quote = data[random.randint(0, len(data))]
toot = quote
mastodon.status_post(toot, media_ids=None, visibility='unlisted')
if __name__ == '__main__':
sys.exit(main())

2258
quotes.dat Normal file

File diff suppressed because it is too large Load Diff

64
replacevars.py Normal file
View File

@ -0,0 +1,64 @@
import sys
import os.path as op
# --------------------------------------------------
VARIABLES = {
'[PC Guild Rank]\nLike in \"[PC Guild Rank], what can be said. We are the few, the proud, the ... under-paid! HarHarHar!\"':
'[PC Guild Rank]',
'[Speaker\'s Name]\nLike in \"But perhaps [Speaker\'s Name] should not speak about this in public. And who would listen, anyway?\"':
'[Speaker\'s Name]',
'[PC Name]\nLike in \"[PC Name]. Once before, Lord Nerevar thought Dagoth Ur and all his kin were dead.\"':
'[PC Name]',
'[PC Race]\nLike in \"I don\'t like you, [PC Race]. You better stay out of this.\"':
'[PC Race]',
'[PC Rank]\nLike in \"What do you want, [PC Rank]?\"':
'[PC Rank]',
'[Next PC Rank]\nLike in "You are now [PC Name] the [Next PC Rank] in the Fighters Guild.\"':
'[Next PC Rank]',
'[Faction]\nLike in \"The [Faction] can forgive your actions this one time only, [PC Rank] [PC Name].\"':
'[Faction]',
'[Rank]\nLike in \"I\'ve risen to [Rank] rank in this outfit by being smart and careful.\"':
'[Rank]',
'[Name]\nLike in \"Hello, [PC Name]. I\'m [Name], and I\'m here to clean out this den of Daedra worshippers.\"':
'[Name]'
}
# Replaces [macros] with strings you want
def main():
with open('quotes.dat', 'r', encoding='utf-8') as file:
quotes = file.readlines()
replacer = ''
if (input('Do you want to remove broken strings? y/n ') == 'y'):
quotes.remove('The Elder Scrolls III: Morrowind\n')
for quote in quotes:
if (len(quote) < 5 or not quote.strip().endswith('\"') or not quote.strip().startswith('\"')):
quotes.remove(quote)
for to_print, to_replace in VARIABLES.items():
while not replacer.strip():
replacer = input('\n' + to_print + '\n Input what do you want to replace ' + to_replace + ' with:')
for i, quote in enumerate(quotes):
quotes[i] = quote.replace(to_replace, replacer)
replacer = ''
with open('quotes.dat', 'w', encoding='utf-8') as file:
for quote in quotes:
print(quote, file=file, end='')
if __name__ == '__main__':
sys.exit(main())

19
requirements.txt Normal file
View File

@ -0,0 +1,19 @@
requests==2.22.0
requests-oauthlib==1.2.0
beautifulsoup4==4.8.0
certifi==2019.6.16
chardet==3.0.4
decorator==4.4.0
idna==2.8
lxml==4.3.4
Mastodon.py==1.4.6
oauthlib==3.0.2
PySocks==1.7.0
python-dateutil==2.8.0
python-docx==0.8.10
python-magic==0.4.15
pytz==2019.2
six==1.12.0
soupsieve==1.9.2
tweepy==3.8.0
urllib3==1.25.3