Skip to content

Instantly share code, notes, and snippets.

@KyleRConway
Created November 14, 2018 02:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KyleRConway/e57b38e74ab07d6fcb46ee6f9813286a to your computer and use it in GitHub Desktop.
Save KyleRConway/e57b38e74ab07d6fcb46ee6f9813286a to your computer and use it in GitHub Desktop.
dicewarebot
from mastodon import Mastodon
from random import randint
import tweepy
# diceroll() takes two arguments:
# number of sides *and* total rolls
def diceroll(di,num):
total_rolls = 1
for i in range(num):
print(randint(1,di))
# diceware() rolls exactly 5 six-sided dice
# and returns 5 numbers in a string (e.g. 11111)
def diceware():
count = 1
dicewarenum = []
for i in range(5):
dicewarenum.append(randint(1,6))
word = str(''.join(map(str, dicewarenum)))
return(word)
# dicepic() converts the 5 numbers in a string
# to unicode depictions of dice rolls
# (e.g. from 55532 to ⚄⚄⚄⚂⚁)
def dicepic(word):
for i in word:
dicepic = word.replace('1','⚀ ')
dicepic = dicepic.replace('2','⚁ ')
dicepic = dicepic.replace('3','⚂ ')
dicepic = dicepic.replace('4','⚃ ')
dicepic = dicepic.replace('5','⚄ ')
dicepic = dicepic.replace('6','⚅ ')
return(dicepic.rstrip())
password = []
dice_words = {}
for i in range(6):
wordlist = open('eff_large_wordlist.txt')
roll = diceware()
for line in wordlist:
linum = line[:5]
if roll == linum:
dice_words[dicepic(roll)] = str(line[5:])
password.append(line[5:].strip() + "-")
else:
continue
# Prep Content
pwd = "\n" + "".join(password)
rolls_and_words = []
for dice, word in dice_words.items():
match = str(dice + "→#" + word.strip())
rolls_and_words.append(match.strip())
#create message
intro_and_dice = "#letsroll\n\n" + '%s' % '\n'.join(map(str, rolls_and_words))
password_hyphen = "\n" + pwd.rstrip("-")
closing_tag = "\n\nRoll your own @ https://www.eff.org/deeplinks/2016/07/new-wordlists-random-passphrases"
toot = intro_and_dice + password_hyphen + closing_tag
tweet = intro_and_dice + password_hyphen + closing_tag
wordlist.close()
#########################
###### MASTODON STUFF
#########################
# Set Variables for Mastodon Login
client_id = ''
client_secret = ''
access_token = ''
base_url = 'https://botsin.space'
# Login to Mastodon API
api = Mastodon(client_id, client_secret, access_token, base_url)
# Send TOOT!!!
api.toot(toot)
#########################
###### TWITTER STUFF
#########################
# Set variables for Twitter Login
t_consumer_key = ''
t_consumer_secret = ''
t_access_token = ''
t_access_token_secret = ''
# Login
# Access and authorize our Twitter credentials from credentials.py
t_auth = tweepy.OAuthHandler(t_consumer_key, t_consumer_secret)
t_auth.set_access_token(t_access_token, t_access_token_secret)
t_api = tweepy.API(t_auth)
# send tweet
t_api.update_status(tweet)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment