コード例 #1
0
ファイル: api.py プロジェクト: JaredNC/Python_Project
def api_id2():
    try:
        if 'id1' in request.args:
            team1 = min(int(request.args['id1']), 5000)
        else:
            return "Team 1 invalid."

        team = bat.Team(team1)
        lvl = team.analyze()

    except:
        return "Problem with team id."

    if int(request.args['thread']) > 0:
        thread_id = int(request.args['thread'])
    else:
        thread_id = 1054931

    try:
        new_b = bat.BattleBB(team1, f"Random*{lvl}")
        test, winner = new_b.battle_bb()
        new = nc.NewcivLogin()
        new_p = new.make_newpost(test, thread_id)
        print(f"Success! Winner: {winner}")
        return "Success."
    except:
        print(f"Failure! Team1: {team1} Team2: Random*{lvl}")
        return "Failure."
コード例 #2
0
ファイル: api.py プロジェクト: JaredNC/Python_Project
def api_id():
    try:
        if 'id1' in request.args:
            team1 = min(int(request.args['id1']), 5000)
        else:
            return "Team 1 invalid."

        if 'id2' in request.args:
            team2 = min(int(request.args['id2']), 5000)
        else:
            return "Team 2 invalid."

        team1 = 0 if team1 == team2 else team1
    except:
        return "Problem with team ids."

    try:
        new_b = bat.BattleBB(team1, team2)
        test, winner = new_b.battle_bb()
        new = nc.NewcivLogin()
        new_p = new.make_newpost(test, 1054931)
        print(f"Success! Winner: {winner}")
        return "Success."
    except:
        print(f"Failure! Team1: {team1} Team2: {team2}")
        return "Failure."
コード例 #3
0
def post(update, context):
    args = update.message.text.split("^")
    new = nc.NewcivLogin()
    new_p = new.make_newpost(args[0][6:], args[1])
    context.bot.send_message(chat_id=update.effective_chat.id,
                             text="Posted in thread {0}".format(new_p.url),
                             disable_web_page_preview=True)
    print("post cmd: " + args[1] + " " + args[0][6:])
コード例 #4
0
ファイル: api.py プロジェクト: JaredNC/Python_Project
def api_id3():
    try:
        if 'id1' in request.args:
            team1 = min(int(request.args['id1']), 5000)
        else:
            return "Team 1 invalid."

        team = bat.Team(team1)
        lvl = team.analyze()

    except:
        return "Problem with team id."

    if int(request.args['thread']) > 0:
        thread_id = int(request.args['thread'])
    else:
        return "Problem with thread."

    try:
        new_b = bat.BattleBB(team1, f"Random*{lvl}")
        test, winner = new_b.battle_bb()
        new = nc.NewcivLogin()
        new_p = new.make_newpost(test, thread_id)
        print(f"Success! Winner: {winner}")

        total = 0
        for pokemon in team.members:
            total += pokemon.level

        exp_array = []
        for pokemon in team.members:
            exp = 5 + pokemon.level / total * lvl
            if winner.user_id != '15':
                exp_array.append(round(exp))
            else:
                exp_array.append(round(exp / 2))

        new = nc.NewcivLogin()
        exp_str = ','.join(map(str, exp_array))
        print(f"Team:{team.team_id} and exp:{exp_str}")
        new_r = new.reward_team(team.team_id, exp_str)
        return "Success."
    except:
        print(f"Failure! Team1: {team1} Team2: Random*{lvl}")
        return "Failure."
コード例 #5
0
ファイル: battle.py プロジェクト: JaredNC/Python_Project
 def grab_team(self, team_id):
     new = nc.NewcivLogin()
     team, name, user_id = new.get_team(team_id)
     pokemon = []
     for x in team:
         dump = x.split(',')
         pokemon.append(
             Pokemon(dump[0], dump[1], int(dump[2]), int(dump[3]),
                     int(dump[4]), dump[5]))
     return pokemon, name, user_id
コード例 #6
0
def hof(update, context):
    user = update.effective_message.reply_to_message.from_user.first_name
    msg = update.effective_message.reply_to_message.text
    new_post = user + ": " + msg
    new = nc.NewcivLogin()
    new.make_newpost(new_post, 1054689)
    context.bot.send_message(
        chat_id=update.effective_chat.id,
        text="HoF'd",
        reply_to_message_id=update.effective_message.message_id)
    print("hof: " + new_post)
コード例 #7
0
def thread(update, context):
    args = update.message.text.split("^")
    new = nc.NewcivLogin()
    new_t = new.make_newthread(args[0][8:], args[1], args[2])
    context.bot.send_message(
        chat_id=update.effective_chat.id,
        text=
        "Posted in forum https://forums.novociv.org/forumdisplay.php?{0} thread {1}"
        .format(args[2], new_t.url),
        disable_web_page_preview=True)
    print("thread cmd: F- " + args[2] + " T-" + args[0][6:] + " P-" + args[1])
コード例 #8
0
def quote(update, context):
    user = update.effective_message.reply_to_message.from_user.first_name
    user2 = update.effective_message.from_user.first_name
    msg = update.effective_message.reply_to_message.text
    args = update.message.text.split("^")
    new_post = "[quote=" + user + " via Telegram]" + msg + "[/quote]" + user2 + ": " + args[
        0][7:]
    new = nc.NewcivLogin()
    new_p = new.make_newpost(new_post, args[1])
    context.bot.send_message(chat_id=update.effective_chat.id,
                             text="Posted in thread {0}".format(new_p.url),
                             disable_web_page_preview=True)
    print("quote: " + new_post)
コード例 #9
0
def post_photo(update, context):
    link = photo(update, context)
    user = update.effective_message.from_user.first_name
    user2 = update.effective_message.reply_to_message.from_user.first_name
    args = update.message.text.split("^")
    newpost = "[quote=" + user + " via Telegram]" + args[0][11:] + "[/quote]" \
                                                                   "Image by: " + user2 + \
                                                                   "\n\n[img]" + link + "[/img]"
    new = nc.NewcivLogin()
    new_p = new.make_newpost(newpost, args[1])
    context.bot.send_message(chat_id=update.effective_chat.id,
                             text="Posted in thread {0}".format(new_p.url),
                             disable_web_page_preview=True)
    print("post cmd: " + args[1] + " " + args[0][6:])
コード例 #10
0
def get_post(update, context):
    query = update.message.text[10:]
    if query.isdigit():
        new = nc.NewcivLogin()
        try:
            new_p = new.get_post_contents(query)
            info = (new_p['text'][:1000] +
                    '..') if len(new_p['text']) > 1002 else new_p['text']
            context.bot.send_message(chat_id=update.effective_chat.id,
                                     text="{0}:\n".format(new_p['url']) + info,
                                     disable_web_page_preview=True)
        except:
            context.bot.send_message(chat_id=update.effective_chat.id,
                                     text="Not a valid post number!")
    else:
        context.bot.send_message(chat_id=update.effective_chat.id,
                                 text="Not a valid post number!")
    print("get_post: " + query)
コード例 #11
0
def battle(update, context):
    args = update.message.text.split("^")
    team1 = args[0][8:]
    team2 = args[1]
    team1 = 0 if team1 == team2 else team1
    try:
        new_b = bat.BattleBB(team1, team2)
        test, winner = new_b.battle_bb()
        new = nc.NewcivLogin()
        new_p = new.make_newpost(test, 1054931)
        context.bot.send_message(
            chat_id=update.effective_chat.id,
            text=f"Winner: {winner}. Details Posted in thread {new_p.url}",
            disable_web_page_preview=True)
    except:
        context.bot.send_message(chat_id=update.effective_chat.id,
                                 text="Not a valid team!")

    print(f"battle cmd: T1-{team1} T2-{team2}")
コード例 #12
0
ファイル: battle_post.py プロジェクト: JaredNC/Python_Project
import newciv_bot as nc
import battle as bat
import sys

print(sys.argv)
print(f"Test: {sys.argv[1]} Test2: {sys.argv[2]}")

a = min(int(sys.argv[1]), 5000)
b = min(int(sys.argv[2]), 5000)
a = 0 if a == b else a


try:
    new_b = bat.BattleBB(a, b)
    test, winner = new_b.battle_bb()
    new = nc.NewcivLogin()
    new_p = new.make_newpost(test, 1054931)
    print(f"Success! Winner: {winner}")
except:
    print(f"Failure! a: {a} b: {b}")
コード例 #13
0
ファイル: api.py プロジェクト: JaredNC/Python_Project
def api_id4():
    timestamp = int(time.time())
    with open(f"log/{timestamp}.txt", 'w') as f:
        sys.stdout = f
        print("hello", flush=True)

        try:
            if 'id1' in request.args:
                team1 = min(int(request.args['id1']), 5000)
            else:
                return "Team 1 invalid."

            team = bat.Team(team1)
            lvl = team.analyze()

        except:
            return "Problem with team id."

        if int(request.args['thread']) > 0:
            thread_id = int(request.args['thread'])
        else:
            return "Problem with thread."

        if 'type' in request.args:
            type = min(int(request.args['type']), 99)
        else:
            return "Invalid Gen or Gym."

        gen = np.floor(type / 10)
        badge = type % 10
        print(f"Gym*{lvl}*{gen}*{badge}", flush=True)

        try:
            new_b = bat.BattleBB(team1, f"Gym*{lvl}*{gen}*{badge}")
            test, winner = new_b.battle_bb()
            new = nc.NewcivLogin()
            new_p = new.make_newpost(test, thread_id)
            print(f"Success! Winner: {winner}", flush=True)

            total = 0
            for pokemon in team.members:
                total += pokemon.level

            exp_array = []
            for pokemon in team.members:
                exp = 5 + pokemon.level / total * lvl
                if winner.user_id != '15':
                    exp_array.append(round(exp))
                else:
                    exp_array.append(round(exp / 2))

            new = nc.NewcivLogin()
            exp_str = ','.join(map(str, exp_array))
            print(f"Team:{team.team_id} and exp:{exp_str}", flush=True)
            new_r = new.reward_team(team.team_id, exp_str)
            if winner.user_id == team.user_id:
                new_gym = new.reward_gym(team.user_id, gen, badge, thread_id)
                print(f"Team:{team.team_id} and result:{new_gym}", flush=True)
                if new_gym != 'Good':
                    new_gym = new.reward_gym(team.user_id, gen, badge,
                                             thread_id)
            return "Success."
        except:
            print(f"Failure! Team1: {team1} Team2: Gym*{lvl}*{gen}*{badge}",
                  flush=True)
            return "Failure."