Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Tox InviteMe Bot
#!/usr/bin/env python
#
# @file echo.py
# @author Wei-Ning Huang (AZ) <aitjcize@gmail.com>
#
# Copyright (C) 2013 - 2014 Wei-Ning Huang (AZ) <aitjcize@gmail.com>
# All Rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
import sys
from tox import Tox, OperationFailedError
from time import sleep, time
from os.path import exists
from random import randint
#SERVER = ["54.199.139.199", 33445, "7F9C31FE850E97CEFD4C4591DF93FC757C7C12549DDD55F8EEAECC34FE76C029"]
SERVER = ["192.254.75.98", 33445, "951C88B7E75C867418ACDB5D273821372BB5BD652740BCDF623A4FA293E75D2F"]
DATA = 'inviteme.data'
class InviteMeBot(Tox):
def __init__(self):
if exists(DATA):
self.load_from_file(DATA)
self.set_name("InviteMeBot")
print('ID: %s' % self.get_address())
self.connect()
self.in_group = False
self.join_group = False
def connect(self):
print('connecting...')
self.bootstrap_from_address(SERVER[0], SERVER[1], SERVER[2])
def loop(self):
checked = False
try:
while True:
status = self.isconnected()
if not checked and status:
print('Connected to DHT.')
checked = True
if checked and not status:
print('Disconnected from DHT.')
self.connect()
checked = False
try:
self.do()
except OperationFailedError as e:
print e
continue
sleep(0.01)
except KeyboardInterrupt:
self.save_to_file(DATA)
def on_group_invite(self, friend_number, group_public_key):
print('Group invite from %s: %s' % (friend_number, group_public_key))
self.join_groupchat(friend_number, group_public_key)
self.in_group = True
def on_group_message(self, group_number, friend_group_number, message):
print('Group message from %s, %s: %s' % (group_number, friend_group_number, message))
#self.group_message_send(group_number, message)
def on_friend_request(self, pk, message):
print('Friend request from %s: %s' % (pk, message))
self.add_friend_norequest(pk)
print('Accepted.')
def on_friend_message(self, friendId, message):
name = self.get_name(friendId)
print('%s: %s' % (name, message))
#self.send_message(friendId, message)
if message == 'invite' and self.in_group:
self.invite_friend(friendId, 0)
print('Invited %s to %s' % (friendId, 0))
if len(sys.argv) == 2:
DATA = sys.argv[1]
t = InviteMeBot()
t.loop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.